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 感谢大佬!

 
posted @ 2021-04-06 10:14  python界泥石流  阅读(3606)  评论(0编辑  收藏  举报