当前位置: 首页 > Web前端 > vue.js

vue-router的push和replace的区别

时间:2023-03-31 15:47:40 vue.js

vue-router的push和replace的区别1.this.$router.push()说明:跳转到不同的url,但是这个方法会在historystack,点击返回返回上一页。2.this.$router.replace()说明:同样是跳转到指定的url,但是这个方法不会在历史中添加新的记录,点击return,会跳转到上一页。之前的记录不存在。3.this.$router.go(n)相对于当前页面向前或向后跳转多少页,类似于window.history.go(n)。n可以是正数或负数。正数返回上一页router.go(n)====window.history.go//浏览器记录前进一步,相当于history.forward()router.go(1)//前进一步backrecord,相当于history.back()router.go(-1)//向前3步记录router.go(3)//如果history记录不够,会静默失败router.go(-100)router.go(100)