Skip to content

Commit

Permalink
fix: loosen navLink active matching
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jan 1, 2021
1 parent c4b4f5a commit 8a2ff33
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions src/client/theme-default/composables/navLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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)$/, '')
}

0 comments on commit 8a2ff33

Please sign in to comment.