vue清除路由历史记录

vue清除路由历史记录

为什么要清除路由历史记录?
从A页面→B页面→C页面,想要直接返回A页面

1、router.push("/HomePage");或router.push({ path: "/HomePage" });向 history 栈增加一条记录
2、router.push({ path: "/HomePage", replace: true });并不增加 history 记录而是替换当前的 history 记录

3、A页面→B页面→C页面,点返回键到A页面。
在B页面→C页面的时候使用
router.push({ path: "/C页面路由", replace: true });
这个时候相当于 history 栈上之后A页面和C页面,A页面就是C页面的上一个页面,所以就实现了点返回键回到A页面

我们也可以用原生的方法来替换,实现同等效果
window.location.href = "http://localhost:8080/HomePage";增加 history 记录
window.location.replace("http://localhost:8080/HomePage");替换 history 记录

原文链接:https://blog.csdn.net/maple_leaf_red/article/details/118085628

你可能感兴趣的:(vue清除路由历史记录)