Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to current location: "/xxx". at createRouterError 的说明和解决
错误说明
Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to current location: "/xxx". at createRouterError
这个错误是说着在promise里捕获了一个导航的重复定义,因为这里是使用编程式导航去进行路由跳转的,$router.push方法会返回一个promise对象。在这里重复的push了同一个路由地址,所以就报了这个错误。
有时也会报这个错Uncaught (in promise) Error: Navigation cancelled from "/xxx" to "/xxx" with a new navigation
具体例子可看下面。
错误定位
<template>
<div @click="toDetail(item.articleId)">
<el-button @click="toDetail(item.articleId)">阅读</el-button>
</div>
</template>
<script>
export default{
methods:{
toDetail(id) {
this.$router.push({ name: 'detail', params: { articleId: id } })
}
}
}
</script>
因为el-button是在div里的,所按钮点击的时候会有两个click都调用了相同的push
错误解决
方法一
把嵌套的子元素中的触发路由的事件去掉,这里把el-button中的click去掉就行了。
方法二
因为这个错误是在push中抛出的,所以在其中捕获catch这个错误就行了,不过这似乎是个治标不治本的办法,所有在push中的错误都可以用此法捕获。
在路由中,添加如下代码进行配置:
import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)
// 捕获push replace中的错误
// 当然在replace中的错误也是可以相同的进行捕获
const originalPush = VueRouter.prototype.push
const originalReplace = VueRouter.prototype.replace
// push
VueRouter.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)
}
// replace
VueRouter.prototype.replace = function push(location, onResolve, onReject) {
if (onResolve || onReject) return originalReplace.call(this, location, onResolve, onReject)
return originalReplace.call(this, location).catch(err => err)
}
Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to current location: "/xxx". at createRouterError 的说明和解决的更多相关文章
- Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to 解决办法
main.js 配置如下 import Router from 'vue-router'; //路由导航冗余报错(路由重复) const originalPush = Router.prototype ...
- Vue 路由跳转报错 Error: Avoided redundant navigation to current location: "/XXX".
在router文件夹下的index.js中加入红色字体代码即可解决 import Vue from 'vue' import VueRouter from 'vue-router' Vue.use(V ...
- Vue Avoided redundant navigation to current location Error
这个报错的根源就是vue-router组件,错误内容翻译一下是: Avoided redundant navigation to current location === 避免冗余导航到当前位置 这个 ...
- vue-router 报错、:Avoided redundant navigation to current location 错误、路由重复
在用vue-router 做单页应用的时候重复点击一个跳转的路由会出现报错 这个报错是重复路由引起的只需在注册路由组建后使用下方重写路由就可以 const originalReplace = VueR ...
- Avoided redundant navigation to current location: "/users"
问题产生的原因:在Vue导航菜单中,重复点击一个菜单,即重复触发一个相同的路由,会报错,但不影响功能 解决:在router的配置文件中加入如下代码: const originalPush = Rout ...
- vue报错 Uncaught (in promise) NavigationDuplicated {_name:""NavigationDuplicated"... 的解决方法
在进行跳转的时候报错 app.js:87499 Uncaught (in promise) NavigationDuplicated?{_name: "NavigationDuplicate ...
- Uncaught (in promise) NavigationDuplicated {_name: "NavigationDuplicated"}的解决方法
左侧菜单栏时,发现点击路由跳转相同地址 会有这个报错 Uncaught (in promise) NavigationDuplicated {_name: "NavigationDuplic ...
- vue报错vue-router.esm.js?8c4f:2007 Uncaught (in promise) NavigationDuplicated {_name: "NavigationDuplicated", name: "NavigationDuplicated"}
今天在写vue项目配置好路由点击菜单时,突然在控制台报错. 错误信息如下: Uncaught (in promise) NavigationDuplicated {_name: "Navig ...
- vue-router Uncaught (in promise) NavigationDuplicated 错误
使用 vue-router 编程式实现页面跳转 this.$router.replace({ path: '/pub' }); 出现错误如下图 原因:vue-router 在 3.1 版本之后把 th ...
- vue router 报错: Uncaught (in promise) NavigationDuplicated {_name:""NavigationDuplicated"... 的解决方法
参考资料:https://blog.csdn.net/zy21131437/article/details/99548983
随机推荐
- 「AntV」景点轨迹数据获取与L7可视化
1. 引言 L7 地理空间数据可视分析引擎是一种基于 WebGL 技术的地理空间数据可视化引擎,可以用于实现各种地理空间数据可视化应用.L7 引擎支持多种数据源和数据格式,包括 GeoJSON.CSV ...
- 性能测试系列:高可用测试linux常用命令
一 linux常用 df –h 看磁盘 du –h –max-depth=1 查看当前目录下,各个文件夹大小 ls –lht 查看当前目录下,各个文件大小 top –H –p pid 看进程下线程的资 ...
- 《.NET内存管理宝典 》(Pro .NET Memory Management) 阅读指南 - 第7章
本章勘误: 暂无,等待细心的你告诉我哦. 本章注解: 暂无 本章释疑: 暂无,等待你的提问 致谢: MVP 林德熙 MVP 吕毅 sPhinX 相关链接 试读记录
- verilog设计知识集合(2)
verilog设计知识集合(2) 1.阻塞与非阻塞 阻塞赋值是存在先后关系的,非阻塞是不存在先后关系的.一般而言,阻塞用于组合逻辑,非阻塞用于时序逻辑(不一定).阻塞的执行时逐步赋值,非阻塞是同步赋值 ...
- python爬虫爬取科技报告数据,共计40余万条(来自国家科技报告服务系统)
按学科分类[中图分类] 共计三十余万条科技报告数据 爬取的网址:https://www.nstrs.cn/kjbg/navigation !!! 如果要完整地跑起来代码,需要先看一下我的这篇博客,完成 ...
- #prim,gcd#UVA12716 GCD XOR&洛谷 1550 [USACO08OCT]Watering Hole G
UVA12716 GCD XOR 题目 \[\sum_{i=1}^{n}\sum_{j=i}^n[\gcd(i,j)==i\;xor\;j] \] 分析 首先来证明一下如果上式成立,那么\(i\;xo ...
- #启发式合并,LIS,平衡树#洛谷 4577 [FJOI2018]领导集团问题
题目 在一棵树上选择最多的点,使得存在祖先关系的点满足\(w_x\leq w_y\),其中\(x\)是\(y\)的祖先 分析 祖先链上要满足\(LIS\),考虑将子节点的LIS序列合并至节点\(x\) ...
- #树链剖分,树上启发式合并#CF741D Arpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths
题目 分析 考虑回文串当且仅当最多有一个字母出现奇数次, 可以记录某个二进制状态的最大深度, 一种就是点\(x\)到某个点,另一种就是经过点\(x\)的一条路径 在\(x\)的子树中递归实现,重儿子保 ...
- C# 循环与条件语句详解
C# Switch 语句 使用 switch 语句选择要执行的多个代码块中的一个. 示例: switch(expression) { case x: // 代码块 break; case y: // ...
- java延迟队列DelayQueue及底层优先队列PriorityQueue实现原理源码详解
DelayQueue是基于java中一个非常牛逼的队列PriorityQueue(优先队列),PriorityQueue是java1.5新加入的,当我看到Doug Lea大神的署名之后,我就知道这个队 ...