需求:
1.我们登录成功后,回跳到上一次浏览的页面
类似于淘宝、京东的访客模式
第一种解决方案
思路分析: 我们会发现响应的数据会经过响应拦截器,发现通过window.location.hash=hash这个语句可以来调整地址栏的地址,状态码403/401拦截后,利用window.location.href将页面重定向到指定的路由地址(登录页),登录成功后,获取传递过来的url 参数,最后进行回跳(京东、淘宝、苏宁都是这种方式进行回跳)
实现过程
1.在拦截器里跳转传递url参数到登录页
// 添加响应拦截器
axios.interceptors.response.use(function (response) {
// 对响应数据做点什么
if(response.data.statusCode == 401 || response.data.statusCode == 403){
Toast.fail(response.data.message)
console.log(window.location.hash); // #/articleDetail/12
window.location.href = '#/login?returnurl=' + window.location.hash.<