fix: 优化路由守卫逻辑,确保从登录页面重定向到首页
This commit is contained in:
@@ -4,6 +4,9 @@ export function createRouterGuard(router: Router) {
|
|||||||
router.beforeEach(async (to, from, next) => {
|
router.beforeEach(async (to, from, next) => {
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
if (to.meta.requiresAuth && !userStore.isAuthenticated) {
|
if (to.meta.requiresAuth && !userStore.isAuthenticated) {
|
||||||
|
if (from.path === "/auth/login") {
|
||||||
|
return next("/");
|
||||||
|
}
|
||||||
const redirect = encodeURIComponent(to.fullPath);
|
const redirect = encodeURIComponent(to.fullPath);
|
||||||
return next({ path: "/auth/login", query: { redirect } });
|
return next({ path: "/auth/login", query: { redirect } });
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user