From 6dde98eb787c614bd89ebab1608ad7e2697a37c6 Mon Sep 17 00:00:00 2001 From: userquin Date: Sat, 11 Feb 2023 15:58:49 +0100 Subject: [PATCH] chore: restore nav side item click state --- components/nav/NavSideItem.vue | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) 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()" >