fix: loosen navLink active matching

pull/198/head
Evan You 4 years ago
parent c4b4f5a5ea
commit 8a2ff33bf8

@ -13,8 +13,9 @@ export function useNavLink(item: DefaultTheme.NavItemWithLink) {
const props = computed(() => {
return {
class: {
active:
normalizePath(withBase(item.link)) === normalizePath(route.path),
active: normalizePath(route.path).startsWith(
normalizePath(withBase(item.link))
),
isExternal
},
href: isExternal ? item.link : withBase(item.link),
@ -31,14 +32,8 @@ export function useNavLink(item: DefaultTheme.NavItemWithLink) {
}
function normalizePath(path: string): string {
path = path
return path
.replace(/#.*$/, '')
.replace(/\?.*$/, '')
.replace(/\.html$/, '')
if (path.endsWith('/')) {
path += 'index'
}
return path
.replace(/\.(html|md)$/, '')
}

Loading…
Cancel
Save