fix(路由): 修正登录和注销后的跳转逻辑
修复登录成功后未正确处理重定向参数的问题,并调整注销后的跳转路径为首页。同时移除登录页面中不必要的重定向检查逻辑,简化路由守卫处理。
Showing
3 changed files
with
6 additions
and
10 deletions
| 1 | /* | 1 | /* |
| 2 | * @Date: 2025-03-20 20:36:36 | 2 | * @Date: 2025-03-20 20:36:36 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2025-03-21 16:25:52 | 4 | + * @LastEditTime: 2025-03-21 15:59:36 |
| 5 | * @FilePath: /mlaj/src/router/index.js | 5 | * @FilePath: /mlaj/src/router/index.js |
| 6 | * @Description: 文件描述 | 6 | * @Description: 文件描述 |
| 7 | */ | 7 | */ |
| ... | @@ -133,7 +133,7 @@ const router = createRouter({ | ... | @@ -133,7 +133,7 @@ const router = createRouter({ |
| 133 | } | 133 | } |
| 134 | }) | 134 | }) |
| 135 | 135 | ||
| 136 | -// TAG: 需要登录才能访问的路由 | 136 | +// 需要登录才能访问的路由 |
| 137 | const authRequiredRoutes = [ | 137 | const authRequiredRoutes = [ |
| 138 | '/profile', | 138 | '/profile', |
| 139 | '/profile/activities', | 139 | '/profile/activities', |
| ... | @@ -147,12 +147,6 @@ const authRequiredRoutes = [ | ... | @@ -147,12 +147,6 @@ const authRequiredRoutes = [ |
| 147 | router.beforeEach((to, from, next) => { | 147 | router.beforeEach((to, from, next) => { |
| 148 | const currentUser = JSON.parse(localStorage.getItem('currentUser')) | 148 | const currentUser = JSON.parse(localStorage.getItem('currentUser')) |
| 149 | 149 | ||
| 150 | - // 如果是登录页面且有redirect参数,未登录用户直接跳转到首页 | ||
| 151 | - if (to.path === '/login' && to.query.redirect && !currentUser) { | ||
| 152 | - next('/') | ||
| 153 | - return | ||
| 154 | - } | ||
| 155 | - | ||
| 156 | // 检查是否需要认证 | 150 | // 检查是否需要认证 |
| 157 | if (authRequiredRoutes.some(route => to.path.startsWith(route))) { | 151 | if (authRequiredRoutes.some(route => to.path.startsWith(route))) { |
| 158 | if (!currentUser) { | 152 | if (!currentUser) { | ... | ... |
| ... | @@ -156,7 +156,9 @@ const handleSubmit = async () => { | ... | @@ -156,7 +156,9 @@ const handleSubmit = async () => { |
| 156 | }) | 156 | }) |
| 157 | 157 | ||
| 158 | if (success) { | 158 | if (success) { |
| 159 | - router.push('/') | 159 | + // 如果有重定向参数,登录成功后跳转到对应页面 |
| 160 | + const redirect = $route.query.redirect | ||
| 161 | + router.push(redirect || '/') | ||
| 160 | } else { | 162 | } else { |
| 161 | error.value = '登录失败,请检查您的凭据' | 163 | error.value = '登录失败,请检查您的凭据' |
| 162 | } | 164 | } | ... | ... |
| ... | @@ -233,7 +233,7 @@ const handleCheckInSuccess = () => { | ... | @@ -233,7 +233,7 @@ const handleCheckInSuccess = () => { |
| 233 | // Handle logout | 233 | // Handle logout |
| 234 | const handleLogout = () => { | 234 | const handleLogout = () => { |
| 235 | logout(); | 235 | logout(); |
| 236 | - router.push("/login"); | 236 | + router.push("/"); |
| 237 | }; | 237 | }; |
| 238 | 238 | ||
| 239 | // Handle menu item click | 239 | // Handle menu item click | ... | ... |
-
Please register or login to post a comment