路由跳转如何让用户不能返回上一个页面

362 阅读1分钟

我们可以使用router.replace方法:

在进行页面跳转时,使用router.replace方法而不是router.push方法。router.replace会替换当前的路由记录,而不会添加新的历史记录,因此用户无法通过浏览器的返回按钮返回到上一个页面。 示例代码:

this.$router.replace('/target-page');

image.png

也可以打印路由查看 options.history.state 里面的区别