Vuex如何避免 NavigationDuplicated: Avoided redundant navigation to current location

问题描述

在这里插入图片描述

		出现这个原因在于Vue-router在3.1之后把$router.push()方法改为了Promise。
		所以当没有回调函数的时候,错误信息就会交给全局的路由错误处理,因此就
		会报上述的错误。即使出现了这个错误,对我们的界面渲染也没什么影响,
		强迫症一点就可以采用下面代码直接复制过去或者降版本~~~

解决方式

Vue.use(VueRouter);

//获取原型对象上的push函数
const originalPush = VueRouter.prototype.push
//修改原型对象中的push方法
VueRouter.prototype.replace = function replace(location) {
    
    
    return originalPush.call(this, location).catch(err => err)
}

猜你喜欢

转载自blog.csdn.net/qq_16733389/article/details/113556721