问题:
vue-router 重复指向一个router导致的报错:
NavigationDuplicated: Avoided redundant navigation to current location: “/login” 或者
Uncaught (in promise) Error: Navigation cancelled from “/” to “/login” with a new navigation.
解决方案:
给push、replace的原型上方法改写一下
// 解决报错
const originalPush = Router.prototype.push
const originalReplace = Router.prototype.replace
// push
Router.prototype.push = function push (location, onResolve, onReject) {
if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
return originalPush.call(this, location).catch(err => err)
}
// replace
Router.prototype.replace = function push (location, onResolve, onReject) {
if (onResolve || onReject) return originalReplace.call(this, location, onResolve, onReject)
return originalReplace.call(this, location).catch(err => err)
}
Vue.use(Router);