Skip to content

Commit 8a2ff33

Browse files
committed
fix: loosen navLink active matching
1 parent c4b4f5a commit 8a2ff33

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

src/client/theme-default/composables/navLink.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ export function useNavLink(item: DefaultTheme.NavItemWithLink) {
1313
const props = computed(() => {
1414
return {
1515
class: {
16-
active:
17-
normalizePath(withBase(item.link)) === normalizePath(route.path),
16+
active: normalizePath(route.path).startsWith(
17+
normalizePath(withBase(item.link))
18+
),
1819
isExternal
1920
},
2021
href: isExternal ? item.link : withBase(item.link),
@@ -31,14 +32,8 @@ export function useNavLink(item: DefaultTheme.NavItemWithLink) {
3132
}
3233

3334
function normalizePath(path: string): string {
34-
path = path
35+
return path
3536
.replace(/#.*$/, '')
3637
.replace(/\?.*$/, '')
37-
.replace(/\.html$/, '')
38-
39-
if (path.endsWith('/')) {
40-
path += 'index'
41-
}
42-
43-
return path
38+
.replace(/\.(html|md)$/, '')
4439
}

0 commit comments

Comments
 (0)