在Vue路由中遇到Error: Avoided redundant navigation to current location:xxxx;错误,意思是路由重复
在router文件夹下的index.js中加入如下代码,解决该错误
import Vue from 'vue'
import VueRouterfrom 'vue-router'
Vue.use(VueRouter)
// 解决:Uncaught (in promise) NavigationDuplicated;
let originalPush = VueRouter.prototype.push; // 先保存一份 VueRouter.prototype.push方法
let originalRepace = VueRouter.prototype.replace;
VueRouter.prototype.push = function push(location) {
// call(); 篡改上下文 catch(); 捕获异常 ****
return originalPush.call(this, location).catch(e => e);
}
VueRouter.prototype.replace = function replace(location) {
return originalRepace.call(this, location).catch(e => e);
}