问题:启动vue项目后,重复点击路由会报Avoided redundant navigation to current location的错误,虽然不影响运行,但控制台会报错。
解决办法:
这里想要看情况,网上看到的解决方法大多不全面。
如果你是用replace方法更新路由的,那么,在你的路由的index.js中添加如下代码:
import VueRouter from 'vue-router'
const originalReplace = VueRouter.prototype.replace
VueRouter.prototype.replace = function replace(location) {
return originalReplace.call(this, location).catch(err => err);
}
Vue.use(VueRouter)
如果你是用push方法更新路由的,那么,在你的路由的index.js中添加如下代码:
import VueRouter from 'vue-router'
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
return originalPush.call(this, location).catch(err => err)
}
Vue.use(VueRouter)
添加后,控制台报错即可消失。