Skip to content

Commit

Permalink
fix: scroll back to top when tab switch (#3498). resolve #3490
Browse files Browse the repository at this point in the history
  • Loading branch information
xachary authored Jan 5, 2024
1 parent 7ffe172 commit d709dd6
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/router/guard/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
}
Expand Down

0 comments on commit d709dd6

Please sign in to comment.