fix(theme): support custom target and rel in navbar links for mobile (#2400)

pull/2413/head
翠 / green 2 years ago committed by GitHub
parent 489681117f
commit f364a5d1d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -11,8 +11,7 @@ const { theme } = useData()
<template v-for="item in theme.nav" :key="item.text"> <template v-for="item in theme.nav" :key="item.text">
<VPNavScreenMenuLink <VPNavScreenMenuLink
v-if="'link' in item" v-if="'link' in item"
:text="item.text" :item="item"
:link="item.link"
/> />
<VPNavScreenMenuGroup <VPNavScreenMenuGroup
v-else v-else

@ -35,10 +35,7 @@ function toggle() {
<div :id="groupId" class="items"> <div :id="groupId" class="items">
<template v-for="item in items" :key="item.text"> <template v-for="item in items" :key="item.text">
<div v-if="'link' in item" :key="item.text" class="item"> <div v-if="'link' in item" :key="item.text" class="item">
<VPNavScreenMenuGroupLink <VPNavScreenMenuGroupLink :item="item" />
:text="item.text"
:link="item.link"
/>
</div> </div>
<div v-else class="group"> <div v-else class="group">

@ -1,18 +1,24 @@
<script lang="ts" setup> <script lang="ts" setup>
import type { DefaultTheme } from 'vitepress/theme'
import { inject } from 'vue' import { inject } from 'vue'
import VPLink from './VPLink.vue' import VPLink from './VPLink.vue'
defineProps<{ defineProps<{
text: string item: DefaultTheme.NavItemWithLink
link: string
}>() }>()
const closeScreen = inject('close-screen') as () => void const closeScreen = inject('close-screen') as () => void
</script> </script>
<template> <template>
<VPLink class="VPNavScreenMenuGroupLink" :href="link" @click="closeScreen"> <VPLink
{{ text }} class="VPNavScreenMenuGroupLink"
:href="item.link"
:target="item.target"
:rel="item.rel"
@click="closeScreen"
>
{{ item.text }}
</VPLink> </VPLink>
</template> </template>

@ -14,8 +14,7 @@ defineProps<{
<VPNavScreenMenuGroupLink <VPNavScreenMenuGroupLink
v-for="item in items" v-for="item in items"
:key="item.text" :key="item.text"
:text="item.text" :item="item"
:link="item.link"
/> />
</div> </div>
</template> </template>

@ -1,18 +1,24 @@
<script lang="ts" setup> <script lang="ts" setup>
import type { DefaultTheme } from 'vitepress/theme'
import { inject } from 'vue' import { inject } from 'vue'
import VPLink from './VPLink.vue' import VPLink from './VPLink.vue'
defineProps<{ defineProps<{
text: string item: DefaultTheme.NavItemWithLink
link: string
}>() }>()
const closeScreen = inject('close-screen') as () => void const closeScreen = inject('close-screen') as () => void
</script> </script>
<template> <template>
<VPLink class="VPNavScreenMenuLink" :href="link" @click="closeScreen"> <VPLink
{{ text }} class="VPNavScreenMenuLink"
:href="item.link"
:target="item.target"
:rel="item.rel"
@click="closeScreen"
>
{{ item.text }}
</VPLink> </VPLink>
</template> </template>

Loading…
Cancel
Save