vue项目:Navigating to current location (xxx) is not allowed

在路由中添加了和当前路由相同的路由,就会报错:Navigating to current location (xxx) is not allowed
解决方法:在router.js页面:

import Router from 'vue-router'
//  重写路由的push方法--->这个是vue-cli4.x以上的坑
const routerPush = Router.prototype.push
Router.prototype.push = function push(location) {
  return routerPush.call(this, location).catch(error => error)
}

你可能感兴趣的:(vue项目:Navigating to current location (xxx) is not allowed)