重写Router.prototype.push后还报NavigationDuplicated错误的解决方法


 
vue项目路由跳转时控制台出现NavigationDuplicated错误,
message: "Navigating to current location (XXX) is not allowed"。

 

  

 解决办法:

1. 在src\router\index.js 中重写Router.prototype.push

1 const routerPush = Router.prototype.push
2 Router.prototype.push = function push (location) {
3   return routerPush.call(this, location).catch(err => err)
4 }

 

 

2.如果还有报错,检查是否有用大括号 {} 方式引入单个对象或单个组件

如下图:

请修改相应的export,并去掉大括号{},如下图。

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM