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

Loading…
Cancel
Save