Skip to content

Commit 293c57e

Browse files
committed
fix: 🐞 修复 nav 子级的默认 activeMatch 失效问题
1 parent cd03e34 commit 293c57e

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

plugins/vitepress-plugin-permalink/src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,14 @@ const setActiveMatchWhenUsePermalink = (
118118
if (!nav.length) return;
119119

120120
nav.forEach(item => {
121-
if (!item.link || item.link === "/") return;
121+
if (item.link === "/") return;
122122

123123
const link = standardLink(item.link);
124124
// cleanUrls 为 false 时,permalinkToPath 的 key 都会带上 .html
125125
const path = permalinkToPath[cleanUrls ? link : `${link.replace(/\.html/, "")}.html`];
126126

127127
// 官方归档 activeMatch 是一个正则表达式字符串
128128
if (path && !item.activeMatch) item.activeMatch = rewrites.map?.[`${path}.md`]?.replace(/\.md/, "") || path;
129-
if (item.items) setActiveMatchWhenUsePermalink(item.items, permalinkToPath, cleanUrls, rewrites);
129+
if (item.items?.length) setActiveMatchWhenUsePermalink(item.items, permalinkToPath, cleanUrls, rewrites);
130130
});
131131
};

vitepress-theme-tk/src/layout/index.vue

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import CommentTwikoo from "../components/CommentTwikoo.vue";
1616
import CommentArtalk from "../components/CommentArtalk.vue";
1717
import CommentGiscus from "../components/CommentGiscus.vue";
1818
import CommentWaline from "../components/CommentWaline.vue";
19-
import { useRoute } from "vitepress";
2019
2120
defineOptions({ name: "TkLayout" });
2221

0 commit comments

Comments
 (0)