错误说明

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 的说明和解决的更多相关文章

  1. Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to 解决办法

    main.js 配置如下 import Router from 'vue-router'; //路由导航冗余报错(路由重复) const originalPush = Router.prototype ...

  2. Vue 路由跳转报错 Error: Avoided redundant navigation to current location: "/XXX".

    在router文件夹下的index.js中加入红色字体代码即可解决 import Vue from 'vue' import VueRouter from 'vue-router' Vue.use(V ...

  3. Vue Avoided redundant navigation to current location Error

    这个报错的根源就是vue-router组件,错误内容翻译一下是: Avoided redundant navigation to current location === 避免冗余导航到当前位置 这个 ...

  4. vue-router 报错、:Avoided redundant navigation to current location 错误、路由重复

    在用vue-router 做单页应用的时候重复点击一个跳转的路由会出现报错 这个报错是重复路由引起的只需在注册路由组建后使用下方重写路由就可以 const originalReplace = VueR ...

  5. Avoided redundant navigation to current location: "/users"

    问题产生的原因:在Vue导航菜单中,重复点击一个菜单,即重复触发一个相同的路由,会报错,但不影响功能 解决:在router的配置文件中加入如下代码: const originalPush = Rout ...

  6. vue报错 Uncaught (in promise) NavigationDuplicated {_name:""NavigationDuplicated"... 的解决方法

    在进行跳转的时候报错 app.js:87499 Uncaught (in promise) NavigationDuplicated?{_name: "NavigationDuplicate ...

  7. Uncaught (in promise) NavigationDuplicated {_name: "NavigationDuplicated"}的解决方法

    左侧菜单栏时,发现点击路由跳转相同地址 会有这个报错 Uncaught (in promise) NavigationDuplicated {_name: "NavigationDuplic ...

  8. vue报错vue-router.esm.js?8c4f:2007 Uncaught (in promise) NavigationDuplicated {_name: "NavigationDuplicated", name: "NavigationDuplicated"}

    今天在写vue项目配置好路由点击菜单时,突然在控制台报错. 错误信息如下: Uncaught (in promise) NavigationDuplicated {_name: "Navig ...

  9. vue-router Uncaught (in promise) NavigationDuplicated 错误

    使用 vue-router 编程式实现页面跳转 this.$router.replace({ path: '/pub' }); 出现错误如下图 原因:vue-router 在 3.1 版本之后把 th ...

  10. vue router 报错: Uncaught (in promise) NavigationDuplicated {_name:""NavigationDuplicated"... 的解决方法

    参考资料:https://blog.csdn.net/zy21131437/article/details/99548983

随机推荐

  1. 网页端实现Excel转JSON

    1. 引言 有时工作中拿到的数据是Excel表格,要在前端网页上使用,通常需要把文件转为JSON 微软的Microsoft Excel没有导出为JSON的功能,其他的第三方网站又不太信任 开源的Exc ...

  2. docker部署Prometheus

    1.安装运行Prometheus 下面介绍如何使用Prometheus.Grafana.CAdvisor.node-exporter.mysqld-exporter对本机服务器性能.Docker容器. ...

  3. AXI-自定义IP-PS设计

    基于AXI4的自定义IP核的设计 1.实验目标 利用vivado中内置的AXI总线初始化的IP核设计工具,将自己设计的流水灯的PL代码打包成IP核外设,挂在PS上,通过PS上的按钮控制流水灯的开始和结 ...

  4. springBoot打war包部署tomcat

    1.修改maven的pom.xml文件 <packaging>war</packaging> 2.排除springboot内嵌的tomcat <dependency> ...

  5. IGC系列:全分组卷积网络,分组卷积极致使用 | 轻量级网络

    IGC系列网络的核心在分组卷积的极致运用,将常规卷积分解成多个分组卷积,能够减少大量参数,另外互补性原则和排序操作能够在最少的参数量情况下保证分组间的信息流通.但整体而言,虽然使用IGC模块后参数量和 ...

  6. arch 安装xfce

    参照 https://www.cnblogs.com/3V4NZ/p/15330275.html 1.安装linux显示服务器 pacman -S xorg Xorg是一个开源的X Window系统的 ...

  7. Scala 特质(Trait)

    1 package chapter06 2 3 object Test13_Trait { 4 def main(args: Array[String]): Unit = { 5 val studen ...

  8. 02 jQuery选择器

    02 jQuery选择器 jQuery的逻辑和css选择器的逻辑是一样的. // 语法: $(选择器) 可以使用jQuery选择器快速的对页面结构进行操作. 案例: <!DOCTYPE html ...

  9. #根号分治,动态规划#洛谷 5616 [MtOI2019]恶魔之树

    题目传送门 分析 最小公倍数最终一定会被表示成若干个质数指数幂的情况(1的情况就直接乘上二的次幂) 然后每个数的加入相当于对每个质数的指数取最大值,但是如果将每个质数的次数都表示出来状态数很多, 考虑 ...

  10. #启发式合并,LIS,平衡树#洛谷 4577 [FJOI2018]领导集团问题

    题目 在一棵树上选择最多的点,使得存在祖先关系的点满足\(w_x\leq w_y\),其中\(x\)是\(y\)的祖先 分析 祖先链上要满足\(LIS\),考虑将子节点的LIS序列合并至节点\(x\) ...