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