From d709dd67b50a2e2b88cbcce48f19085ce528f971 Mon Sep 17 00:00:00 2001 From: xachary <179740385@qq.com> Date: Fri, 5 Jan 2024 09:54:05 +0800 Subject: [PATCH] fix: scroll back to top when tab switch (#3498). resolve #3490 --- src/router/guard/index.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/router/guard/index.ts b/src/router/guard/index.ts index 660db405e..f643cc272 100644 --- a/src/router/guard/index.ts +++ b/src/router/guard/index.ts @@ -101,11 +101,10 @@ function createScrollGuard(router: Router) { return /^#/.test(href); }; - const body = document.body; - router.afterEach(async (to) => { // scroll top - isHash((to as RouteLocationNormalized & { href: string })?.href) && body.scrollTo(0, 0); + isHash((to as RouteLocationNormalized & { href: string })?.href) && + document.querySelector('.vben-layout-content')?.scrollTo(0, 0); return true; }); }