fix(路由): 恢复登录后重定向功能
修复登录流程中重定向功能被注释的问题,现在未登录用户将被重定向到登录页并携带当前路由信息,登录成功后自动跳转回原页面
Showing
3 changed files
with
8 additions
and
8 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-05-23 14:21:22 | 4 | + * @LastEditTime: 2025-06-13 10:03:08 |
| 5 | * @FilePath: /mlaj/src/router/guards.js | 5 | * @FilePath: /mlaj/src/router/guards.js |
| 6 | * @Description: 路由守卫逻辑 | 6 | * @Description: 路由守卫逻辑 |
| 7 | */ | 7 | */ |
| ... | @@ -67,8 +67,8 @@ export const checkAuth = (to) => { | ... | @@ -67,8 +67,8 @@ export const checkAuth = (to) => { |
| 67 | 67 | ||
| 68 | if (needAuth && !currentUser) { | 68 | if (needAuth && !currentUser) { |
| 69 | // 未登录时重定向到登录页面 | 69 | // 未登录时重定向到登录页面 |
| 70 | - // return { path: '/login', query: { redirect: to.fullPath } } | 70 | + return { path: '/login', query: { redirect: to.fullPath } } |
| 71 | - return { path: '/login' } | 71 | + // return { path: '/login' } |
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | return true | 74 | return true | ... | ... |
| ... | @@ -48,8 +48,8 @@ axios.interceptors.response.use( | ... | @@ -48,8 +48,8 @@ axios.interceptors.response.use( |
| 48 | localStorage.removeItem('currentUser'); | 48 | localStorage.removeItem('currentUser'); |
| 49 | // 跳转到登录页面,并携带当前路由信息 | 49 | // 跳转到登录页面,并携带当前路由信息 |
| 50 | const currentPath = router.currentRoute.value.fullPath; | 50 | const currentPath = router.currentRoute.value.fullPath; |
| 51 | - // router.push(`/login?redirect=${encodeURIComponent(currentPath)}`); | 51 | + router.push(`/login?redirect=${encodeURIComponent(currentPath)}`); |
| 52 | - router.push(`/login`); | 52 | + // router.push(`/login`); |
| 53 | } | 53 | } |
| 54 | return response; | 54 | return response; |
| 55 | }, | 55 | }, | ... | ... |
| ... | @@ -287,9 +287,9 @@ const handleSubmit = async () => { | ... | @@ -287,9 +287,9 @@ const handleSubmit = async () => { |
| 287 | 287 | ||
| 288 | if (success) { | 288 | if (success) { |
| 289 | // 如果有重定向参数,登录成功后跳转到对应页面 | 289 | // 如果有重定向参数,登录成功后跳转到对应页面 |
| 290 | - // const redirect = $route.query.redirect; | 290 | + const redirect = $route.query.redirect; |
| 291 | - // router.push(redirect || "/"); | 291 | + router.push(redirect || "/"); |
| 292 | - router.push("/"); | 292 | + // router.push("/"); |
| 293 | } else { | 293 | } else { |
| 294 | error.value = "登录失败,请检查您的输入项"; | 294 | error.value = "登录失败,请检查您的输入项"; |
| 295 | } | 295 | } | ... | ... |
-
Please register or login to post a comment