|
|
|
@ -8,52 +8,25 @@ export function useNavLink(item: DefaultTheme.NavItemWithLink) {
|
|
|
|
|
const route = useRoute()
|
|
|
|
|
const { withBase } = useUrl()
|
|
|
|
|
|
|
|
|
|
const classes = computed(() => ({
|
|
|
|
|
active: isActive.value,
|
|
|
|
|
external: isExternal.value
|
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
|
const isActive = computed(() => {
|
|
|
|
|
return normalizePath(withBase(item.link)) === normalizePath(route.path)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const isExternal = computed(() => {
|
|
|
|
|
return isExternalCheck(item.link)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const href = computed(() => {
|
|
|
|
|
return isExternal.value ? item.link : withBase(item.link)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const target = computed(() => {
|
|
|
|
|
if (item.target) {
|
|
|
|
|
return item.target
|
|
|
|
|
const isExternal = isExternalCheck(item.link)
|
|
|
|
|
|
|
|
|
|
const props = computed(() => {
|
|
|
|
|
return {
|
|
|
|
|
class: {
|
|
|
|
|
active:
|
|
|
|
|
normalizePath(withBase(item.link)) === normalizePath(route.path),
|
|
|
|
|
isExternal
|
|
|
|
|
},
|
|
|
|
|
href: isExternal ? item.link : withBase(item.link),
|
|
|
|
|
target: item.target || isExternal ? `_blank` : null,
|
|
|
|
|
rel: item.rel || isExternal ? `noopener noreferrer` : null,
|
|
|
|
|
'aria-label': item.ariaLabel
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return isExternal.value ? '_blank' : ''
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const rel = computed(() => {
|
|
|
|
|
if (item.rel) {
|
|
|
|
|
return item.rel
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return isExternal.value ? 'noopener noreferrer' : ''
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const ariaLabel = computed(() => item.ariaLabel)
|
|
|
|
|
|
|
|
|
|
const text = computed(() => item.text)
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
classes,
|
|
|
|
|
isActive,
|
|
|
|
|
isExternal,
|
|
|
|
|
href,
|
|
|
|
|
target,
|
|
|
|
|
rel,
|
|
|
|
|
ariaLabel,
|
|
|
|
|
text
|
|
|
|
|
props,
|
|
|
|
|
isExternal
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|