fix: scroll back to top when tab switch (#3498). resolve #3490

This commit is contained in:
xachary
2024-01-05 09:54:05 +08:00
committed by GitHub
parent 7ffe1726b9
commit d709dd67b5

View File

@@ -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;
});
}