首页 > 作文

关于用户没有权限路由守卫跳转登录后页面跳转,返回之前浏览页面处理方法

更新时间:2023-04-04 07:04:46 阅读: 评论:0

路由守卫需要登录跳转后重回页面

问题:当我们访问页面需要token,路由守卫就会使跳转到登录页面,这时如我们没有进行重定向就会跳转到个首页或者人中心页面。解决方法:在响应拦截器里面,没有token的状态码进行判断,捕获401状态码

设置响应拦截
跳转带hash参数
window.location.href = /#/login?redirectURL=${window.location.hash.substr(1)}

axios.interceptors.respon.u(function (respon) {     // 对响应数据做点什么    if (respon.data.statusCode == 401) {         window.location.href = `/#/login?redirectURL=${ window.location.hash.substr(1)} `           //当请求返回401,用户没有登录,直接送回首页 加上hash参数    }    return respon;}, function (error) {     // 对响应错误做点什么    return Promi.reject(error);});

登录页面获取hash为 console.log(window.location.hash)

 console.log(window.location.hash)  //得到 /#/login?redirectURL=%2Farticaldetail%2F12

关键我们需要

decodeURIComponen1报名nt(window.location.hash.split("=")[1])  //得到 /articaldetail/12

登录页面,需要判定url有无带值
但是没有值的时候也会是字符串’undefined’

if ( decodeURIComponent(window.location.hash.split("=")[1]) && 蚝油生菜的做法步骤// 这个有可能值为undefined 也不能跳转decodeURIComponent(window.location.hash.split("=")[1]) !="undefined") { console.log(decodeURIComponent(window.location.hash.split("=")[1]));  /护理学/ 没用decodeURIComponent高中班级管理制度转钱 /#/login?redirectURL=%2Farticaldetail%2F12 // 用decodeURIComponent转后 /articaldetail/12     this.$router绝对值的化简方法口诀.push({          path: decodeURIComponent(window.location.hash.split("=")[1]),         }); } el {  //没有带hash,我们直接跳到个人中心      this.$router.push({  path: `/personal/${ res.data.data.ur.id}` }); }

这样我们就能跳转到用户没有登录前的页面,增加用户体验

本文地址:https://blog.csdn.net/weixin_50462008/article/details/109394417

本文发布于:2023-04-04 07:04:45,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/zuowen/5bc30030879941e80ede1daefb47b715.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

本文word下载地址:关于用户没有权限路由守卫跳转登录后页面跳转,返回之前浏览页面处理方法.doc

本文 PDF 下载地址:关于用户没有权限路由守卫跳转登录后页面跳转,返回之前浏览页面处理方法.pdf

下一篇:返回列表
标签:页面   跳转   跳转到   用户
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图