错误说明

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. eviacam在Arch/Manjaro Linux下的安装

    安装base-devel 安装编译工具,默认的依赖里没有编译工具 sudo yay -S base-devel 如果安装编译工具,会报类似下面的错误: 安装eviacam yay -S eviacam ...

  2. nginx完全卸载删除

    nginx卸载 其实很简单,只需要两步即可完成! 第一步:输入以下指令全局查找nginx相关的文件: sudo find / -name nginx* 第二步:删除查找出来的所有nginx相关文件 s ...

  3. 基础教材系列:编译原理——B站笔记

    一.编译器是什么 源程序→预处理器→经过预处理的源程序→编译器→汇编语言程序→汇编器→可重定位的机器代码→链接器/加载器→目标机器代码. 编译器的结构: 与源语言相关:字符流→词法分析器→词法单元流→ ...

  4. 【JVM】关于JVM,你需要知道这些!!

    写在前面 最近,一直有小伙伴让我整理下关于JVM的知识,经过十几天的收集与整理,初版算是整理出来了.希望对大家有所帮助. JDK 是什么? JDK 是用于支持 Java 程序开发的最小环境. Java ...

  5. docker安装es-header及相关问题解决

    安装es-header docker pull mobz/elasticsearch-head:5 docker run --restart=always --name elasticsearch-h ...

  6. NetAdapt:MobileNetV3用到的自动化网络简化方法 | ECCV 2018

    NetAdapt的思想巧妙且有效,将优化目标分为多个小目标,并且将实际指标引入到优化过程中,能够自动化产生一系列平台相关的简化网络,不仅搜索速度快,而且得到简化网络在准确率和时延上都于较好的表现   ...

  7. Azkaban 2.5 Documentation

    Overview Azkaban was implemented at LinkedIn to solve the problem of Hadoop job dependencies. We had ...

  8. #树状数组,离散#洛谷 3586 [POI2015]LOG

    题目 分析 考虑\(\geq s\)的部分最多取到\(s\), 设\(<s\)的总和为\(p\),个数为\(t\), 那么\(p+(n-t)*s\geq c*s\)就一定能取到 代码 #incl ...

  9. OpenHarmony轻松玩转GIF数据渲染

    OpenAtom OpenHarmony(以下简称"OpenHarmony")提供了Image组件支持GIF动图的播放,但是缺乏扩展能力,不支持播放控制等.今天介绍一款三方库--o ...

  10. Aspose.Cells使用总结大全

    引用:https://blog.csdn.net/u011555996/article/details/79000270 使用到 Aspose.Cells 插件,整理一下. 一:新建解决方案,目录如下 ...