fix: 优化路由守卫逻辑,确保从登录页面重定向到首页

This commit is contained in:
2025-12-22 21:08:05 +07:00
parent 65ad60d0d2
commit 7fa87ba08b

View File

@@ -4,6 +4,9 @@ export function createRouterGuard(router: Router) {
router.beforeEach(async (to, from, next) => {
const userStore = useUserStore();
if (to.meta.requiresAuth && !userStore.isAuthenticated) {
if (from.path === "/auth/login") {
return next("/");
}
const redirect = encodeURIComponent(to.fullPath);
return next({ path: "/auth/login", query: { redirect } });
}