update: 更新router包一些小细节,和一些注释

This commit is contained in:
XiaoDaiGua-Ray 2023-12-15 11:23:51 +08:00
parent 7c51a5c78f
commit 0c9105b54e
2 changed files with 7 additions and 8 deletions

View File

@ -93,10 +93,14 @@ export const orderRoutes = (routes: AppRouteRecordRaw[]) => {
/**
*
* 切换路由时, 手动将容器区域回归默认值
* @param route 路由对象
*
* 由于官方不支持这个方法了, 所以自己手写了一个
* 如果需要忽略恢复默认位置, 仅需要在 meta 中配置 ignoreAutoResetScroll 属性即可
* 当路由切换后自动将内容区域滚动到顶部(x、y都会归于 0),如果需要忽略该功能,可以在路由的 meta 中配置 ignoreAutoResetScroll 属性
*
* @example
* scrollViewToTop({
* meta: { ignoreAutoResetScroll: true }
* }) // 不会滚动到顶部,维持上一次的滚动位置
*/
export const scrollViewToTop = (route: RouteLocationNormalized) => {
const { meta } = route

View File

@ -21,11 +21,6 @@ const createVueRouter = async () => {
routes: (await constantRoutes()) as unknown as RouteRecordRaw[],
scrollBehavior: (to) => {
scrollViewToTop(to)
return {
top: 0,
left: 0,
}
},
})
}