Skip to content

Commit 1522c7d

Browse files
committed
修复登录的 redirect 地址,存在参数时,登录成功回跳的时候地址不正确的问题
1 parent f57af58 commit 1522c7d

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

src/permission.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ router.beforeEach((to, from, next) => {
4848
// 在免登录白名单,直接进入
4949
next()
5050
} else {
51-
next(`/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页
51+
const redirect = encodeURIComponent(to.fullPath) // 编码 URI,保证参数跳转回去后,可以继续带上
52+
next(`/login?redirect=${redirect}`) // 否则全部重定向到登录页
5253
NProgress.done()
5354
}
5455
}

src/views/login.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ export default {
190190
// 验证码开关
191191
this.captchaEnable = getCaptchaEnable();
192192
// 重定向地址
193-
this.redirect = this.$route.query.redirect;
193+
this.redirect = this.$route.query.redirect ? decodeURIComponent(this.$route.query.redirect) : undefined;
194194
this.getCookie();
195195
},
196196
methods: {

src/views/socialLogin.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export default {
117117
// 验证码开关
118118
this.captchaEnable = getCaptchaEnable();
119119
// 重定向地址
120-
this.redirect = this.$route.query.redirect;
120+
this.redirect = this.$route.query.redirect ? decodeURIComponent(this.$route.query.redirect) : undefined;
121121
// 社交登录相关
122122
this.type = this.$route.query.type;
123123
this.code = this.$route.query.code;

0 commit comments

Comments
 (0)