diff --git a/components/nav/NavSideItem.vue b/components/nav/NavSideItem.vue index 5c0d222f..317e9497 100644 --- a/components/nav/NavSideItem.vue +++ b/components/nav/NavSideItem.vue @@ -14,8 +14,27 @@ defineSlots<{ default: {} }>() +const nuxtApp = useNuxtApp() const router = useRouter() +const allowScrollTop = ref(false) + +const restoreClickHook = () => { + if (isHydrated.value) { + if (typeof props.to === 'string') + allowScrollTop.value = router.currentRoute.value.fullPath === props.to + else + allowScrollTop.value = router.currentRoute.value.name === props.to.name + } +} + +router.afterEach(() => { + allowScrollTop.value = false +}) + +nuxtApp.hooks.hook('app:suspense:resolve', restoreClickHook) +nuxtApp.hooks.hook('page:finish', restoreClickHook) + useCommand({ scope: 'Navigation', @@ -51,7 +70,7 @@ const noUserVisual = computed(() => isHydrated.value && props.userOnly && !curre :active-class="activeClass" group focus:outline-none disabled:pointer-events-none :tabindex="noUserDisable ? -1 : null" - @click="$trackScroll.forceScrollToTop()" + @click="allowScrollTop && $trackScroll.forceScrollToTop()" >