重寫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