vue h5 路由回退到指定页面
背景:从列表页入口依次进入:列表页 -> 详情页 -> 开发票页 (a -> b -> c)
现状:开完发票后 回到 详情页, 在详情页 点击 后退,又 回到了发票页 (c -> b, b-> c 来回跳)
改进: 详情页回退到 列表页 (c->b, b-> a)
1. 列表页 to 详情页的跳转 使用正常的
this.$router.to('/detail/xxx')
2. 详情页 to 开票页 使用
this.$router.replace('/invoice/xxx')
3. 开票页 to 详情页, 使用
this.$router.replace(`/detail/xxx`)
这样只在入口处 使用 this.$router.to , 其余使用 this.$router.replace 就可以了。
主要是 区分 this.$router.to, this.$router.replace
- router.push 方法会向 history 栈添加一个新的记录,所以,当用户点击浏览器后退按钮时,会回到之前的 URL。
- router.replace 在导航时不会向 history 添加新记录,而是取代了当前的条目。
Every day deserves to be expected