mirror of https://github.com/halo-dev/halo
perf: improve router scrollBehavior configuration (#3834)
#### What type of PR is this? /kind improvement /area console /milestone 2.5.x #### What this PR does / why we need it: 修改 Vue Router 的 scrollBehavior 配置,添加是否是不同路由的跳转,如果是才会在跳转之后滚动到页面顶部。可以解决在 https://github.com/halo-dev/halo/issues/3833 中提到的打开附件详情之后,列表滚动到顶部的问题。这是因为在打开附件详情的时候会修改路由的参数。 #### Which issue(s) this PR fixes: Fixes #3833 #### Special notes for your reviewer: 测试方式: 1. 上传若干附件,滚动到列表底部。 2. 然后打开某个附件详情,观察列表是否自动滚动到了顶部,如果没有,则修改有效。 #### Does this PR introduce a user-facing change? ```release-note None ```pull/3845/head
parent
1681be36d6
commit
d0cc9005b0
|
@ -1,4 +1,9 @@
|
||||||
import { createRouter, createWebHashHistory } from "vue-router";
|
import {
|
||||||
|
createRouter,
|
||||||
|
createWebHashHistory,
|
||||||
|
type RouteLocationNormalized,
|
||||||
|
type RouteLocationNormalizedLoaded,
|
||||||
|
} from "vue-router";
|
||||||
import routesConfig from "@/router/routes.config";
|
import routesConfig from "@/router/routes.config";
|
||||||
import { setupPermissionGuard } from "./guards/permission";
|
import { setupPermissionGuard } from "./guards/permission";
|
||||||
import { setupCheckStatesGuard } from "./guards/check-states";
|
import { setupCheckStatesGuard } from "./guards/check-states";
|
||||||
|
@ -7,7 +12,14 @@ import { setupAuthCheckGuard } from "./guards/auth-check";
|
||||||
const router = createRouter({
|
const router = createRouter({
|
||||||
history: createWebHashHistory(import.meta.env.BASE_URL),
|
history: createWebHashHistory(import.meta.env.BASE_URL),
|
||||||
routes: routesConfig,
|
routes: routesConfig,
|
||||||
scrollBehavior: () => ({ left: 0, top: 0 }),
|
scrollBehavior: (
|
||||||
|
to: RouteLocationNormalized,
|
||||||
|
from: RouteLocationNormalizedLoaded
|
||||||
|
) => {
|
||||||
|
if (to.name !== from.name) {
|
||||||
|
return { left: 0, top: 0 };
|
||||||
|
}
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
setupAuthCheckGuard(router);
|
setupAuthCheckGuard(router);
|
||||||
|
|
Loading…
Reference in New Issue