1,应用场景
A页面跳转到对应的查看器B(可返回A),B可跳转到C(可返回B),C可跳转到B(可返回C),循环跳转正确返回对应页面。
2,解决方法
利用sessionStorage缓存跳转前的路径。每一次进行跳转时进行缓存当前的路径。在进行需要返回时取出最新的路径,并从缓存中进行删除,进行对应的跳转返回。
缺点(只适合跳转-》返回,不适合页面间既可以跳转又可以进行面包屑等页面切换,会导致存入的缓存路径不正确)。
3,代码演示A->B
3.1,A页面跳转前存入当前路径
toMy(){
//跳转到对应的路径
let path = '/home/ToHome'
//存入当前路径(页面返回取出)
let fromPath = '/home/ToMy'
// 从sessionStorage中获取已有的路径数组数据,如果没有则创建一个空数组
let pathArray = JSON.parse(sessionStorage.getItem('pathArray')) || [];
// 将跳转前的路径添加到数组中
pathArray.push(fromPath);
// 将包含路径信息的数组转换为字符串并存入sessionStorage
sessionStorage.setItem('pathArray', JSON.stringify(pathArray));
this.$router.push({
path,
query: { ReportInfo: row,index:1},
})
}
3.2,B返回A取出缓存路径进行返回
back(){
let stringPath= JSON.par