Skip to content

登录支持来源重定向

通过用户中心分享出去的url未登陆则跳转到登录页,登录完成则重定向到来源地址

整体流程

  1. 判断是否登录,如未登录,则通过 encodeURIComponent 对当前url编码转译,并通过url传参query名为redirect重定向至登录页;
  2. 登录页通过 decodeURIComponent 对来源url进行解码
  3. 登录成功跳转至来源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;