|
|
|
@ -11,11 +11,22 @@ export function useNavLink(item: DefaultTheme.NavItemWithLink) {
|
|
|
|
|
const isExternal = isExternalCheck(item.link)
|
|
|
|
|
|
|
|
|
|
const props = computed(() => {
|
|
|
|
|
const routePath = normalizePath(route.path)
|
|
|
|
|
|
|
|
|
|
let active = false
|
|
|
|
|
if (item.activeMatch) {
|
|
|
|
|
active = new RegExp(item.activeMatch).test(routePath)
|
|
|
|
|
} else {
|
|
|
|
|
const itemPath = normalizePath(withBase(item.link))
|
|
|
|
|
active =
|
|
|
|
|
itemPath === '/'
|
|
|
|
|
? itemPath === routePath
|
|
|
|
|
: routePath.startsWith(itemPath)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
class: {
|
|
|
|
|
active: normalizePath(route.path).startsWith(
|
|
|
|
|
normalizePath(withBase(item.link))
|
|
|
|
|
),
|
|
|
|
|
active,
|
|
|
|
|
isExternal
|
|
|
|
|
},
|
|
|
|
|
href: isExternal ? item.link : withBase(item.link),
|
|
|
|
@ -36,4 +47,5 @@ function normalizePath(path: string): string {
|
|
|
|
|
.replace(/#.*$/, '')
|
|
|
|
|
.replace(/\?.*$/, '')
|
|
|
|
|
.replace(/\.(html|md)$/, '')
|
|
|
|
|
.replace(/\/index$/, '/')
|
|
|
|
|
}
|
|
|
|
|