Skip to content

Commit

Permalink
fix: active class on sidebar links
Browse files Browse the repository at this point in the history
  • Loading branch information
Jinjiang committed Aug 9, 2023
1 parent 25f0cb0 commit c31974a
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/vitepress/components/VPSidebarLink.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts" setup>
import { useData } from 'vitepress'
import { ref, inject, onMounted } from 'vue'
import { ref, inject, onMounted, watchPostEffect } from 'vue'
import { MenuItemWithLink } from '../../core'
import { isActive } from '../support/utils'
Expand All @@ -13,17 +13,16 @@ const closeSideBar = inject('close-sidebar') as () => void
// https://github.com/vuejs/theme/issues/97#issuecomment-1666562964
const active = ref(false)
const checkActive = () => {
return isActive(page.value.relativePath, props.item.link)
const updateActive = () => {
active.value = isActive(page.value.relativePath, props.item.link)
}
onMounted(() => {
active.value = checkActive()
})
onMounted(updateActive)
watchPostEffect(updateActive)
</script>

<template>
<a
:class="{ link: true, active: active || checkActive() }"
:class="{ link: true, active }"
:href="item.link"
@click="closeSideBar"
>
Expand Down

0 comments on commit c31974a

Please sign in to comment.