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)