现象: 路由切换后页面调用this.$router.back()回退,会跳过一个历史记录,回退到倒数第二个页面
原因: 在全局前置守卫 router.beforeEach中对next做了如下处理:
next({replace:true,path: to.path,query: { ...to.query, ...query }}),
去掉replace这个配置后发现,调用replace方法的地方,会生成两条记录
找了一下vue-router中beforeEach实现中对next几种参数的处理
next 参数为对象时 replace属性没有配置时,默认会调用push方法,所以history 会多一条记录。