登录支持来源重定向
通过用户中心分享出去的url未登陆则跳转到登录页,登录完成则重定向到来源地址
整体流程
- 判断是否登录,如未登录,则通过
encodeURIComponent对当前url编码转译,并通过url传参query名为redirect重定向至登录页; - 登录页通过
decodeURIComponent对来源url进行解码 - 登录成功跳转至来源url
用户中心示例代码
javascript
// 示例代码
const redirectUrl = encodeURIComponent(window.location.href);
window.location.href = `//login.kanjian.com?redirect=${redirectUrl}`;登录示例代码
javascript
// 示例代码
// 成功的回调重定向
const redirectUrl = decodeURIComponent(this.$route.query.redirect);
window.location.href = redirectUrl;