vue router报错 NavigationDuplicated {_name: "NavigationDuplicated", name: "NavigationDuplicated"}的解决办法
其原因在于Vue-router在3.1之后把$router.push()方法改为了Promise。所以假如没有回调函数,错误信息就会交给全局的路由错误处理,因此就会报上述的错误。
禁止全局路由错误处理打印,这个也是vue-router开发者给出的解决方案:
const originalPush = Router.prototype.push Router.prototype.push = function push(location) { return originalPush.call(this, location).catch(err => err) }
把这段代码放在引入vue-router之后,一般在main.js里,如果你的路由单独抽取出来了,就放在路由文件中。
import Vue from "vue";
import Router from "vue-router";
//Vue-router在3.1之后把$router.push()方法改为了Promise。所以假如没有回调函数,错误信息就会交给全局的路由错误处理,因此就会报上述的错误。
//解决方案:禁止全局路由错误处理打印,这个也是vue-router开发者给出的解决方案
const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
return originalPush.call(this, location).catch(err => err)
}
Vue.use(Router);

浙公网安备 33010602011771号