From be30faaa0fc14946ff5f0804fe14b4f82377a69c Mon Sep 17 00:00:00 2001 From: userquin Date: Sun, 8 Jan 2023 17:33:19 +0100 Subject: [PATCH] chore: avoid scroll to top when switching tabs --- components/common/CommonRouteTabs.vue | 13 +++++++++++-- components/notification/NotificationCard.vue | 2 +- plugins/remember-scroll-position.client.ts | 3 ++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/components/common/CommonRouteTabs.vue b/components/common/CommonRouteTabs.vue index 75ca06e6..dc2850e5 100644 --- a/components/common/CommonRouteTabs.vue +++ b/components/common/CommonRouteTabs.vue @@ -15,6 +15,7 @@ const { options, command, replace, preventScrollTop = false } = $defineProps<{ }>() const router = useRouter() +const nuxtApp = useNuxtApp() useCommands(() => command ? options.map(tab => ({ @@ -24,7 +25,15 @@ useCommands(() => command icon: tab.icon ?? 'i-ri:file-list-2-line', onActivate: () => router.replace(tab.to), })) - : []) + : [], +) + +const handleClick = (to: RouteLocationRaw) => { + if (preventScrollTop || nuxtApp.$preventScrollToTop(router.resolve(to).fullPath)) + return + + nuxtApp.$scrollToTop() +}