错误提示:NavigationDuplicated: Avoided redundant navigation to current location:
在router.js文件中(也可能是router文件下的index.js)加上如下图所示代码段即可。
//获取原型对象上的push函数
const originalPush = Router.prototype.push
//修改原型对象中的push方法
Router.prototype.push = function push(location) {
return originalPush.call(this, location).catch(err => err)
}
插入如下位置
Vue.use(VueRouter);
//获取原型对象上的push函数
const originalPush = VueRouter.prototype.push;
//修改原型对象中的push方法
VueRouter.prototype.push = function push(location) {
return originalPush.call(this, location).catch((err) => err);
};
注意:VueRouter 要和下面的一致,否则报错未定义