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)
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容