hookehuyr

fix(路由): 修正登录和注销后的跳转逻辑

修复登录成功后未正确处理重定向参数的问题,并调整注销后的跳转路径为首页。同时移除登录页面中不必要的重定向检查逻辑,简化路由守卫处理。
/*
* @Date: 2025-03-20 20:36:36
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-03-21 16:25:52
* @LastEditTime: 2025-03-21 15:59:36
* @FilePath: /mlaj/src/router/index.js
* @Description: 文件描述
*/
......@@ -133,7 +133,7 @@ const router = createRouter({
}
})
// TAG: 需要登录才能访问的路由
// 需要登录才能访问的路由
const authRequiredRoutes = [
'/profile',
'/profile/activities',
......@@ -147,12 +147,6 @@ const authRequiredRoutes = [
router.beforeEach((to, from, next) => {
const currentUser = JSON.parse(localStorage.getItem('currentUser'))
// 如果是登录页面且有redirect参数,未登录用户直接跳转到首页
if (to.path === '/login' && to.query.redirect && !currentUser) {
next('/')
return
}
// 检查是否需要认证
if (authRequiredRoutes.some(route => to.path.startsWith(route))) {
if (!currentUser) {
......
......@@ -156,7 +156,9 @@ const handleSubmit = async () => {
})
if (success) {
router.push('/')
// 如果有重定向参数,登录成功后跳转到对应页面
const redirect = $route.query.redirect
router.push(redirect || '/')
} else {
error.value = '登录失败,请检查您的凭据'
}
......
......@@ -233,7 +233,7 @@ const handleCheckInSuccess = () => {
// Handle logout
const handleLogout = () => {
logout();
router.push("/login");
router.push("/");
};
// Handle menu item click
......