解决报错Uncaught (in promise) Error: Redirected when going from …
对Router原型链上的push、replace方法进行重写,这样就不用每次调用方法都要加上catch。
// 解决Vue-Router升级导致的Uncaught(in promise) navigation guard问题
在src/router/index.js中添加:
import Router from 'vue-router';
const originalPush = VueRouter.prototype.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方法同上
// 解决Vue-Router升级导致的Uncaught(in promise) navigation guard问题
const originalReplace = VueRouter.prototype.replace
Router.prototype.replace = function replace (location, onResolve, onReject) {
if (onResolve || onReject) return originalReplace.call(this, location, onResolve, onReject)
return originalPush.call(this, location).catch(err => err)
}