当前位置:网站首页>解决报错:Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to current location: “
解决报错:Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to current location: “
2022-07-23 07:20:00 【薇z】
报错内容:
vue-router.esm.js?68cf:2065 Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to current location: "/search".
at createRouterError (webpack-internal:///./node_modules/[email protected]@vue-router/dist/vue-router.esm.js:1993:15)
at createNavigationDuplicatedError (webpack-internal:///./node_modules/[email protected]@vue-router/dist/vue-router.esm.js:1978:15)
报错图片:

出现报错原因:使用编程式路由实现跳转的时候,多次执行会抛出NavigationDuplicated的警告错误是因为"vue-router"3版本之后 底层引入了promise,而通过声明式导航没有出现此类问题是因为vue-router底层已经处理好了。
解决方法1:在router文件夹下的index.js下添加如下内容
// 解决vue-router在3.0版本以上重复点报错问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
return originalPush.call(this, location).catch(err => err)
}

解决方法2:在router文件夹下的index.js下:
let originPush=VueRouter.prototype.push;
let originReplace=VueRouter.prototype.replace;
//重写push/replace
//第一个参数:告诉原来的push方法,往哪里跳转(传递哪些参数)
//第二个参数:成功的回调
//第三个参数:失败的回调
//call/apply区别
//相同点:都可以调用函数一次,都可以篡改函数的上下文(this)一次‘
//不同点:call/apply传递参数:call传递参数用逗号隔开,apply方法执行,传递数组
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,()=>{},()=>{});
}
}边栏推荐
- Color recognition of regions of interest in pictures and videos based on OpenCV
- 专题讲座5 组合数学 学习心得(长期更新)
- Chapter II relational database after class exercises
- CSDN recommended template
- 数据库系统原理与应用教程(045)—— MySQL 查询(七):聚合函数
- 【JS高级】正则入门基础—关于你想知道的正则表达式_01
- LeetCode_51_N皇后
- [play with FPGA in simple terms to learn 10 ----- simple testbench design]
- Research on hardware architecture of Ti single chip millimeter wave radar xwr1642
- MySQL面试题
猜你喜欢

IP address classification and range

建立STM32F103C8T6工程模板和STM32 ST-LINK Utilit烧录hex文件

【JS高级】正则入门基础—关于你想知道的正则表达式_01

图形管线(一)后处理阶段 alpha测试 模版测试 深度测试 混合

QT creator.Pro file adds the corresponding library according to the kit

Parameters of high-performance JVM

Talking about the CPU type of anroid device and the placement directory of so files
腾讯MMKV的原理与实现

七月到底有多热?通过爬虫爬取当月温度信息,并使用matplotlib绘制温度折线图

魔兽地图编辑器触发器笔记
随机推荐
腾讯MMKV的原理与实现
反常积分的审敛
Starfish OS:以现实为纽带,打造元宇宙新范式
LeetCode_ 52_ Queen n II
数据库系统原理与应用教程(048)—— MySQL 查询(十):自连接查询
面试官:有了解过ReentrantLock的底层实现吗?说说看
[play with FPGA in simple terms to learn 10 ----- simple testbench design]
数据库系统原理与应用教程(040)—— MySQL 查询(二):设置要查询的列名或表达式
图像处理1:RGB888_YCbCr444
How to deal with the new development mode when doing testing?
Vs2019:constexpr function "qcountleadingzerobits" cannot generate constant expressions
Unity关于本地加载图片涉及webrequest或者byte
MATLAB:将PNG图片转成txt文件
2022-07-22 review linked list operation and some problems
Reference and output message types in ROS
关于#redis#的问题:Redis设置数据持久化之后还是会有丢失数据的风险
Optimising a 3D convolutional neural network for head and neck computed tomography segmentation with
企业科技展厅制作需要考虑这五点
SparkSQL设计及入门,220722,
数据库系统原理与应用教程(041)—— MySQL 查询(三):设置查询条件