vue-router报错:Avoided redundant navigation to current location 解决方法

分类:技术最近更新:2020-09-18浏览:2956

在我们引用vue-router时,在同一个路由页里,继续$router.push当前路由页时,会报如下错误:

Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to current location "/"

q.jpg

用如下方式处理:

javascript
import Vue from "vue"; import VueRouter from "vue-router"; /* === */ const originalPush = VueRouter.prototype.push; //修改原型对象中的push方法 VueRouter.prototype.push = function push(location) { return originalPush.call(this, location).catch(err => err); }; /* === */ Vue.use(VueRouter);