其他分享
首页 > 其他分享> > Uncaught (in promise) Error: Redirected when going from "/login" to "/home" via

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

作者:互联网

项目中遇到如下报错内容: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 感谢大佬!

 

标签:via,Uncaught,onResolve,Error,promise,location,router,home
来源: https://www.cnblogs.com/hudaxian/p/14620617.html