订单列表页(A)可进入订单详情页(B),B可进入订单支付页(C),在C支付完成后返回到B,在B页面返回又返回到C,B和C来回跳,此时期待B返回到A,满足C->B,B->A。
方法一
// 清除浏览器历史栈
if (window.history && window.history.pushState) {
// 向历史记录中插入当前页
history.pushState(null, null, document.URL);
window.addEventListener('popstate', onClickLeft, false);
}
onBeforeUnmount(() => {
window.removeEventListener('popstate', onClickLeft, false);
});
使用该方法可满足需求,但是手机移动端右滑返回到上一页面会有卡顿,体验十分不好。
方法二
// 列表页跳转详情页
this.$route.push('/order/detail/:id');
// 详情页跳转支付页
this.$route.replace('/order/:id');
// 支付页跳转详情页
this.$route.replae('/order/detail/:id');
这样只在入口处 使用 this. r o u t e r . p u s h , 其余使用 t h i s . router.push , 其余使用 this. router.push,其余使用this.router.replace 就可以了。
完美解决!