diff --git a/src/router/index.ts b/src/router/index.ts index 3f6a9c3..76c6d2c 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -113,6 +113,14 @@ const allRoutes = [...routes, ...extraRoutes]; const router = createRouter({ history: createWebHashHistory(), routes: allRoutes, + scrollBehavior(to, from, savedPosition) { + // 如果有保存的位置(浏览器前进/后退),则使用保存的位置 + if (savedPosition) { + return savedPosition; + } + // 否则滚动到顶部 + return { top: 0 }; + }, }); export default router;