当我们使用 this.$router.push("/index")跳转到首页,然后再次点击首页就会出现以下这个错误
这是因为我们在当前页面进行了重复跳转,虽然这个错误不影响开发,但是毕竟是一个报错,还是要处理的,处理方法就是在index.js/router文件中添加如下代码
Vue.use(Router)
//获取原型对象上的push函数
const originalPush = Router.prototype.push
//修改原型对象中的push方法
Router.prototype.push = function push(location) {
return originalPush.call(this, location).catch(err => err)
}
这样就不会报错了