vue-router.esm.js:2065 Uncaught (in promise) Error: Redirected when going from "/login?redirect=%2Fhome" to "/home" via a navigation guard.
原因:
vue-router路由版本更新产生的问题,导致路由跳转失败抛出该错误;
真正的原因是由于返回了一个Promise对象, 正常的跳转由then方法执行 当正常的路由跳转, 被"路由导航守卫"拦截并重新指定路由时, 由于 this.$router.push() 返回的是Promise对象, 此时then方法不能正常执行, 无法跳转到指定路由, 就触发了该对象的捕获错误的方法, throw抛出错误, 但并不影响程序功能.
解决方式:
通过重写VueRouter原型对象上的push方法, 覆盖原来抛出异常的方法, "吞掉"异常
切记: 一定要在router创建实例之前
// console.log(VueRouter);
let originPush = VueRouter.prototype.push;
let originReplace = VueRouter.prototype.replace;
// call与apply:相同点:都可以修改this,
// 不同点:传递的参数,call传递多个参数时,以,作为分隔
// apply传递多个参数时,以数组方式进行
// 重写push/replace
// 第一个参数:告诉原来push方法,你往哪里跳转(传递哪些参数)
// 第二个参数:成功的回调
// 第二个参数:失败的回调
VueRouter.prototype.push = function(location,resolve,reject) {
if(resolve && reject) {
originPush.call(this,location,resolve,reject);
}else {
originPush.call(this,location,()=>{},()=>{});
}
}
VueRouter.prototype.replace = function(location,resolve,reject) {
if(resolve && reject) {
originReplace.call(this,location,resolve,reject);
}else {
originReplace.call(this,location,()=>{},()=>{});
}
}
vue-router.esm.js:2065 Uncaught (in promise) Error: Redirected when going from "/login?redirect=%2Fhome" to "/home" via a navigation guard.的更多相关文章
- vue router 报错: Uncaught (in promise) NavigationDuplicated {_name:""NavigationDuplicated"... 的解决方法
参考资料:https://blog.csdn.net/zy21131437/article/details/99548983
- vue.runtime.esm.js:593 [Vue warn]: Invalid prop: custom validator check failed for prop "value".报错解决
在uni中使用 picker组件,一直报错 vue.runtime.esm.js:593 [Vue warn]: Invalid prop: custom validator check failed ...
- 解决"Uncaught (in promise) Error: Navigation cancelled from "/" to "/login" with a new navigation"报错处理
Uncaught (in promise) Error: Navigation cancelled from "/" to "/login" with a ne ...
- Ionic3报错Error: Uncaught (in promise): Error: StaticInjectorError
ERROR Error: Uncaught (in promise): Error: StaticInjectorError[Geolocation]: StaticInjectorError[Geo ...
- axios请求报Uncaught (in promise) Error: Request failed with status code 404
使用axios处理请求时,出现的问题解决 当url是远程接口链接时,会报404的错误: Uncaught (in promise) Error: Request failed with status ...
- vue 运行项目时,Uncaught (in promise) DOMException: Failed to execute 'open' on 'XMLHttpRequest': Invalid URL
npm run dev 运行项目后 验证码显示不出来 并报错 Uncaught (in promise) DOMException: Failed to execute 'open' on 'XML ...
- vue 报错 Uncaught (in promise) error
可尝试在then()后加上catch() ps:该图来自网络
- VUE - vue.runtime.esm.js?6e6d:619 [Vue warn]: Do not use built-in or reserved HTML elements as component i
<script> export default { name:'header' // 不要使用内置或保留的HTML元素 , 改为Header或者置或保留的HTML元素 ...
- Uncaught (in promise) Error: Request failed with status code 500解决方案
今天又学到一种修改bug的方法 : let newpwd = crypto.createHash('md5').update(req.body.upwd).digest('hex'); 在点击按钮加 ...
- Vue报错: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'protocol')
Vue报错: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'protocol') 报错信 ...
随机推荐
- (组合游戏)SG函数与SG定理详解
有一段时间没记录知识类的博客了,这篇博客就说一下SG函数和SG定理吧 SG函数是用于解决博弈论中公平组合游戏(Impartial Combinatorial Games,ICG)问题的一种方法. 什么 ...
- 开源:Taurus.DTS 微服务分布式任务框架,支持即时任务、延时任务、Cron表达式定时任务和广播任务。
前言: 在发布完:开源:Taurus.DTC 微服务分布式事务框架,支持 .Net 和 .Net Core 双系列版本,之后想想,好像除了事务外,感觉里面多了一个任务发布订阅的基础功能. 本想既然都有 ...
- warning: LF will be replaced by CRLF in public/tinymce/langs/zh_CN.js
windows使用git时出现:warning:LF will be replaced by CRLF windows中的换行符为 CRLF, 而在linux下的换行符为LF,所以在执行add . 时 ...
- vue中class样式与内联样式
(1):style使用 <div class="score" :style="{ color: colorComputed(item.status) }" ...
- 线段树 hdu 4027
***又是超时的问题,当一个区间全是1时,再去开方和不开方是一样的,所以在这一步不需要再往底层递归了*** #include <iostream> #include <cstdio& ...
- Spring AOP原来是这样实现的
Spring AOP 技术实现原理 在Spring框架中,AOP(面向切面编程)是通过代理模式和反射机制来实现的.本文将详细介绍Spring AOP的技术实现原理,包括JDK动态代理和CGLIB代理的 ...
- 12_前K个高频元素
前K个高频元素 给你一个整数数组 nums 和一个整数 k ,请你返回其中出现频率前 k 高的元素.你可以按 任意顺序 返回答案.347.力扣题目链接 示例 1: 输入: nums = [1,1,1, ...
- Kubernetes security context capability
注:以下内容基于经验主义,不一定对. Linux capability Linux 中,root 作为特权用户,具有执行所有应用的能力.而普通用户只能执行普通应用.如果普通用户需要执行特权应用,需要进 ...
- springboot - 解决使用pagehelper 报 SQL语句异常
原因: mapper.xml 中的sql加上了分号. <select id="search" resultType="***.Table"> sel ...
- GraduationProject
GraduationProject 为了毕设寻找的一些springboot项目资源 后台项目: FEBS-Shiro: https://github.com/wuyouzhuguli/FEBS-Shi ...