Skip to content

Commit

Permalink
fix: home action link not being reactive (#195) (#212)
Browse files Browse the repository at this point in the history
Co-authored-by: mariotang <mariotang@tencent.com>
  • Loading branch information
ShenQingchuan and mariotang authored Feb 11, 2021
1 parent 6bf0d14 commit 5678dc3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
8 changes: 4 additions & 4 deletions src/client/theme-default/components/NavDropdownLinkItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
</template>

<script setup lang="ts">
import { defineProps } from 'vue'
import { defineProps, toRefs } from 'vue'
import type { DefaultTheme } from '../config'
import { useNavLink } from '../composables/navLink'
import OutboundLink from './icons/OutboundLink.vue'
const { item } = defineProps<{
const props = defineProps<{
item: DefaultTheme.NavItemWithLink
}>()
const { props: linkProps, isExternal } = useNavLink(item)
const propsRefs = toRefs(props);
const { props: linkProps, isExternal } = useNavLink(propsRefs.item)
</script>

<style scoped>
Expand Down
12 changes: 6 additions & 6 deletions src/client/theme-default/components/NavLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
</template>

<script setup lang="ts">
import { defineProps } from 'vue'
import { defineProps, toRefs } from 'vue'
import type { DefaultTheme } from '../config'
import { useNavLink } from '../composables/navLink'
import OutboundLink from './icons/OutboundLink.vue'
const { item } = defineProps<{
item: DefaultTheme.NavItemWithLink
}>()
const { props: linkProps, isExternal } = useNavLink(item)
const props = defineProps<{
item: DefaultTheme.NavItemWithLink,
}>();
const propsRefs = toRefs(props);
const { props: linkProps, isExternal } = useNavLink(propsRefs.item);
</script>

<style scoped>
Expand Down
20 changes: 10 additions & 10 deletions src/client/theme-default/composables/navLink.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import { computed } from 'vue'
import { computed, Ref } from 'vue'
import { useRoute } from 'vitepress'
import type { DefaultTheme } from '../config'
import { isExternal as isExternalCheck } from '../utils'
import { useUrl } from '../composables/url'

export function useNavLink(item: DefaultTheme.NavItemWithLink) {
export function useNavLink(item: Ref<DefaultTheme.NavItemWithLink>) {
const route = useRoute()
const { withBase } = useUrl()

const isExternal = isExternalCheck(item.link)
const isExternal = isExternalCheck(item.value.link)

const props = computed(() => {
const routePath = normalizePath(route.path)

let active = false
if (item.activeMatch) {
active = new RegExp(item.activeMatch).test(routePath)
if (item.value.activeMatch) {
active = new RegExp(item.value.activeMatch).test(routePath)
} else {
const itemPath = normalizePath(withBase(item.link))
const itemPath = normalizePath(withBase(item.value.link))
active =
itemPath === '/'
? itemPath === routePath
Expand All @@ -29,10 +29,10 @@ export function useNavLink(item: DefaultTheme.NavItemWithLink) {
active,
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
href: isExternal ? item.value.link : withBase(item.value.link),
target: item.value.target || isExternal ? `_blank` : null,
rel: item.value.rel || isExternal ? `noopener noreferrer` : null,
'aria-label': item.value.ariaLabel
}
})

Expand Down

0 comments on commit 5678dc3

Please sign in to comment.