File tree Expand file tree Collapse file tree 5 files changed +43
-21
lines changed Expand file tree Collapse file tree 5 files changed +43
-21
lines changed Original file line number Diff line number Diff line change @@ -110,7 +110,7 @@ export const setupRouterGuard = (router: Router) => {
110
110
} catch ( error : any ) {
111
111
// 过程中发生任何错误,都直接重置 Token,并重定向到登录页面
112
112
await userStore . logoutCallBack ( )
113
- next ( `/login?redirect=${ to . path } ` )
113
+ next ( `/login?redirect=${ encodeURIComponent ( to . fullPath ) } ` )
114
114
}
115
115
} else {
116
116
next ( )
@@ -123,7 +123,7 @@ export const setupRouterGuard = (router: Router) => {
123
123
next ( )
124
124
} else {
125
125
// 其他没有访问权限的页面将被重定向到登录页面
126
- next ( ' /login' )
126
+ next ( ` /login?redirect= ${ encodeURIComponent ( to . fullPath ) } ` )
127
127
}
128
128
}
129
129
Original file line number Diff line number Diff line change @@ -100,7 +100,8 @@ http.interceptors.response.use(
100
100
async onOk ( ) {
101
101
const userStore = useUserStore ( )
102
102
await userStore . logoutCallBack ( )
103
- await router . replace ( '/login' )
103
+ const currentPath = router . currentRoute . value . fullPath
104
+ await router . replace ( `/login?redirect=${ encodeURIComponent ( currentPath ) } ` )
104
105
} ,
105
106
} )
106
107
} else {
Original file line number Diff line number Diff line change @@ -124,12 +124,19 @@ const handleLogin = async () => {
124
124
const { redirect, ... othersQuery } = router .currentRoute .value .query
125
125
const { rememberMe } = loginConfig .value
126
126
loginConfig .value .username = rememberMe ? form .username : ' '
127
- await router .push ({
128
- path: (redirect as string ) || ' /' ,
129
- query: {
130
- ... othersQuery ,
131
- },
132
- })
127
+
128
+ // 如果有重定向参数,解码并直接跳转到完整路径
129
+ if (redirect ) {
130
+ const redirectPath = decodeURIComponent (redirect as string )
131
+ await router .push (redirectPath )
132
+ } else {
133
+ await router .push ({
134
+ path: ' /' ,
135
+ query: {
136
+ ... othersQuery ,
137
+ },
138
+ })
139
+ }
133
140
Message .success (' 欢迎使用' )
134
141
} catch (error ) {
135
142
console .error (error )
Original file line number Diff line number Diff line change @@ -72,12 +72,19 @@ const handleLogin = async () => {
72
72
await userStore .emailLogin (form )
73
73
tabsStore .reset ()
74
74
const { redirect, ... othersQuery } = router .currentRoute .value .query
75
- await router .push ({
76
- path: (redirect as string ) || ' /' ,
77
- query: {
78
- ... othersQuery ,
79
- },
80
- })
75
+
76
+ // 如果有重定向参数,解码并直接跳转到完整路径
77
+ if (redirect ) {
78
+ const redirectPath = decodeURIComponent (redirect as string )
79
+ await router .push (redirectPath )
80
+ } else {
81
+ await router .push ({
82
+ path: ' /' ,
83
+ query: {
84
+ ... othersQuery ,
85
+ },
86
+ })
87
+ }
81
88
Message .success (' 欢迎使用' )
82
89
} catch (error ) {
83
90
form .captcha = ' '
Original file line number Diff line number Diff line change @@ -72,12 +72,19 @@ const handleLogin = async () => {
72
72
await userStore .phoneLogin (form )
73
73
tabsStore .reset ()
74
74
const { redirect, ... othersQuery } = router .currentRoute .value .query
75
- await router .push ({
76
- path: (redirect as string ) || ' /' ,
77
- query: {
78
- ... othersQuery ,
79
- },
80
- })
75
+
76
+ // 如果有重定向参数,解码并直接跳转到完整路径
77
+ if (redirect ) {
78
+ const redirectPath = decodeURIComponent (redirect as string )
79
+ await router .push (redirectPath )
80
+ } else {
81
+ await router .push ({
82
+ path: ' /' ,
83
+ query: {
84
+ ... othersQuery ,
85
+ },
86
+ })
87
+ }
81
88
Message .success (' 欢迎使用' )
82
89
} catch (error ) {
83
90
form .captcha = ' '
You can’t perform that action at this time.
0 commit comments