Uncaught (in promise) Error: Redirected when going from "/login" to "/home" via a navigation guard.


項目中遇到如下報錯內容:Uncaught (in promise) Error: Uncaught (in promise) Error: Redirected when going from "/login" to "/home" via a navigation guard.

原因:vue-router路由版本更新產生的問題,導致路由跳轉失敗拋出該錯誤,但並不影響程序功能

解決方案一、

使用編程式導航跳轉時,每次使用,后面都跟上.catch方法,捕獲錯誤信息

this.$router.push('/location').catch(err => ())

解決方案二、

全局解決:替換路由的Push和replace方法,放在src/router/index.js中:

import Router from 'vue-router'

const originalPush = Router.prototype.push
Router.prototype.push = function push(location, onResolve, onReject) {
if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
return originalPush.call(this, location).catch(err => err)
}

 轉載:https://blog.csdn.net/qq_42805569/article/details/111238634 感謝大佬!

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM