From 8a2ff33bf8043b5b0ec21826d7962d7e6337e394 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 1 Jan 2021 11:40:01 -0500 Subject: [PATCH] fix: loosen navLink active matching --- src/client/theme-default/composables/navLink.ts | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/client/theme-default/composables/navLink.ts b/src/client/theme-default/composables/navLink.ts index e4c18d0d..951a00cd 100644 --- a/src/client/theme-default/composables/navLink.ts +++ b/src/client/theme-default/composables/navLink.ts @@ -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)$/, '') }