关于vue.js:vuerouter的push和replace的区别

7次阅读

共计 463 个字符,预计需要花费 2 分钟才能阅读完成。

vue-router 的 push 和 replace 的区别

1.this.$router.push()

形容:跳转到不同的 url,但这个办法会向 history 栈增加一个记录,点击后退会返回到上一个页面。

2.this.$router.replace()

形容:同样是跳转到指定的 url,然而这个办法不会向 history 外面增加新的记录,点击返回,会跳转到上上一个页面。上一个记录是不存在的。

3.this.$router.go(n)

绝对于以后页面向前或向后跳转多少个页面, 相似 window.history.go(n)。n 可为负数可为正数。负数返回上一个页面

router.go(n)====window.history.go

// 在浏览器记录中前进一步,等同于 history.forward()
router.go(1)
 
// 后退一步记录,等同于 history.back()
router.go(-1)
 
// 后退 3 步记录
router.go(3)
 
// 如果 history 记录不够用,那就默默地失败呗
router.go(-100)
router.go(100)
正文完
 0