fix(dashboard): 迁移 router.beforeEach 到 Vue Router 4 返回值写法

This commit is contained in:
LIghtJUNction
2026-03-27 19:09:22 +08:00
parent b25342303f
commit 0497b5fbb9

View File

@@ -22,7 +22,7 @@ interface AuthStore {
has_token(): boolean;
}
router.beforeEach(async (to, from, next) => {
router.beforeEach(async (to, from) => {
if (from.name && from.path !== to.path) {
const loadingStore = useRouterLoadingStore();
loadingStore.start();
@@ -34,17 +34,17 @@ router.beforeEach(async (to, from, next) => {
// 如果用户已登录且试图访问登录页面,则重定向到首页
if (to.path === '/auth/login' && auth.has_token()) {
return next(auth.returnUrl || '/');
return auth.returnUrl || '/';
}
if (to.matched.some((record) => record.meta.requiresAuth)) {
if (authRequired && !auth.has_token()) {
auth.returnUrl = to.fullPath;
return next('/auth/login');
} else next();
} else {
next();
return '/auth/login';
}
}
return true;
});
router.afterEach(() => {