mirror of
https://github.com/AstrBotDevs/AstrBot
synced 2026-07-15 17:30:13 +08:00
fix(dashboard): 迁移 router.beforeEach 到 Vue Router 4 返回值写法
This commit is contained in:
@@ -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(() => {
|
||||
|
||||
Reference in New Issue
Block a user