vue项目中重复加载当前路由会报错,

解决方法:找到项目中的router文件,在里面添加代码,修正Vue原型上的push和replace方法

(注意vue-router的引入名称)

// 缓存原型上的push函数
const originPush = Router.prototype.push
const originReplace = Router.prototype.replace
// 给原型对象上的push指定新函数函数
Router.prototype.push = function (location, onComplete, onAbort) {// 判断如果没有指定回调函数, 通过call调用源函数并使用catch来处理错误if (onComplete===undefined && onAbort===undefined) {return originPush.call(this, location, onComplete, onAbort).catch(() => {})} else { // 如果有指定任意回调函数, 通过call调用源push函数处理originPush.call(this, location, onComplete, onAbort)}
}// replace函数
Router.prototype.replace = function (location, onComplete, onAbort) {if (onComplete===undefined && onAbort===undefined) {return originReplace.call(this, location, onComplete, onAbort).catch(() => {})} else {originReplace.call(this, location, onComplete, onAbort)}
}

可以按需添加,当时我遇到这个问题按照百度上搜索的办法没有解决的原因是因为我项目中用的是replace方法,可是百度上都是修改push方法,导致不生效,现在列出两种push和replace方法的修改代码,看自己用的是哪种方法,按需添加就生效了

vue重复点击路由报错,解决NavigationDuplicated: Avoided redundant navigation to current location: 问题相关推荐

  1. 四种解决Vue中重复点击相同路由控制台报错问题( Avoided redundant navigation to current location)

    vue-router 升级到3.1.x 后,重复点击导航时,控制台出现报错 ,虽然不影响功能使用,但是看的就不舒服. 报错信息 Uncaught (in promise) NavigationDupl ...

  2. 解决NavigationDuplicated: Avoided redundant navigation to current location: 问题

    vue项目中,点击左侧菜单栏中的项,重复点击时会报错,解决这个问题,首先找到项目中管理路由的文件,一般是router/index.js,有的直接就是router.js. 然后看vue-router的引 ...

  3. 如何解决NavigationDuplicated: Avoided redundant navigation to current location:问题

    问题描述 解决方案 废话不多说 打开router下边的index.js文件,然后复制粘贴以下代码段即可 let originPush = VueRouter.prototype.push let or ...

  4. 解决Vue报错:Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to current location

    问题描述:重复点击导航时,控制台出现报错 ,虽然不影响功能使用,但也不能坐视不管. 解决 Vue 重复点击相同路由,出现 Uncaught (in promise) NavigationDuplica ...

  5. 解决报错:Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to current location: “

    报错内容: vue-router.esm.js?68cf:2065 Uncaught (in promise) NavigationDuplicated: Avoided redundant navi ...

  6. vue 跳转报 NavigationDuplicated: Avoided redundant navigation to current location: “/to-do“.

    错误提示:NavigationDuplicated: Avoided redundant navigation to current location: "/to-do". 提示这 ...

  7. 解决Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to current location问题

    在Vue路由中遇到Error: Avoided redundant navigation to current location:xxxx:错误,意思是路由重复 在router文件夹下的index.j ...

  8. 解决vue重复点击路由报错问题:Uncaught (in promise) NavigationDuplicated

    直接在路由router文件夹下加上下面代码: import routes from './router'方法一: const originalPush = Router.prototype.push ...

  9. 解决vue-router报NavigationDuplicated: Avoided redundant navigation to current location: “/login“ 的问题

    一.普遍问题解决方法 import Router from 'vue-router'; Vue.use(Router); // 解决ElementUI导航栏中的vue-router在3.0版本以上重复 ...

最新文章

  1. Arrays.sort()方法
  2. 4.添加监听,使地图随鼠标,键盘移动并改变大小
  3. 那个盗窃比尔·盖茨、马斯克、巴菲特推特账号,发布诈骗广告的少年被捕了!年仅17岁...
  4. 深入了解人工智能机器人的应用领域有哪些?
  5. 【重点】LeetCode 25. Reverse Nodes in k-Group
  6. 优先队列priority_queue的比较函数
  7. w8fuckcdn 通过扫描全网绕过CDN获取网站IP地址
  8. 500多套微精品信小程序源码部分带后台,不同行业的源码集合,适合快速开发和自己学习
  9. 维修iphone6无服务器,苹果6通病——插卡无服务维修思路和教程
  10. 数据挖掘常用的基本技术,主要有哪些?
  11. 解析:深度学习框架Caffe源码
  12. 零基础英语语法速成(一)
  13. React中获取地址栏传参
  14. 后缀001,002,003等的文件解压
  15. matlab 坐标轴居中,MATLAB 把坐标轴(X Y轴)移到坐标原点
  16. 计算机与打印机未连接,win7系统无法打印提示似乎未连接打印机的恢复步骤
  17. 超级计算机控制人的电影,想知道这部电影的名字,讲述通过超级计算机进入人脑.回到过去.其中有个老教授死亡留下一封信给给主角。...
  18. export / import与module.exports/require的关系与用法
  19. 51单片机入门·开篇
  20. 关于P2P下载软件伤硬盘的话题

热门文章

  1. FZU2109 数位dp 含前导零
  2. InnoDB ReplicaSet
  3. flutter 资料整理
  4. JST日本压着端子PH系列线对板连接器的PCB封装库
  5. SpringCloud[01]Eureka服务注册与发现
  6. 数据库基本操作(创建主键、外键以及索引)
  7. Leetcode PHP题解--D35 876. Middle of the Linked List
  8. 自己动手做一款蓝牙小车
  9. 计算机通信网络发展趋势,通信网络的现状及发展方向分析
  10. 品优购商城——列表页