当前位置:网站首页>Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to current location: “/?k=“
Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to current location: “/?k=“
2022-04-22 06:28:00 【Write poetry for you@】
This warning appears

The programmed route jumps to the current route ,( The parameters are the same ), Click to execute multiple times and throw an exception as shown in the figure above , Declarative navigation does not have this warning ,Vue-router The bottom has been handled
The cause of the problem
'vue-router':"^3.5.3": Abreast of the times vue-router Introduced promise
Solution :
1, By giving push perhaps replace Method passes the response successfully 、 Failed callback function , You can capture the current warning , It can solve , This method treats the symptoms but not the root causes , Change a component ( For other components push Method ) You have to push Add failed and successful callbacks .
this.$router.push({name:'search',params:{keyword:this.keyword},query:{k:this.keyword.toUpperCase()}},()=>{},(error)=>{
// console.log(this.$router) // Incoming successful or failed callback resolution ( Capture ) This unusual problem
})
2. Modify the underlying source code , rewrite $router.push And $router.replace Method ( Permanent cure )
First of all, understand : $router yes VueRouter An example of push yes VueRouter The archetypal approach .
// The first VueRouter Of a prototype object push, Save a copy first
let originPush = VueRouter.prototype.push; let originReplace = VueRouter.prototype.replace; //console.log(originPush);
// rewrite push|replace // The first parameter , Tell the original push Method , Where are you going ( What parameters are passed ) VueRouter.prototype.push = function (location, resolve, reject) { //console.log(this); if (resolve && reject) { // otiginPush(); //originPush The context is windows //call||apply difference : The same thing , Can call the function once , Can tamper with the context of a function once // Difference :call And apply Pass parameters :call Pass parameters separated by commas ,apply Method execution m Pass array originPush.call(this, location, resolve, reject) // Tamper with the context } else { originPush.call(this,location, () => { }, () => { }); } } VueRouter.prototype.replace=function(location,resolve,reject){// Where to jump Successful callback Failed callback if(resolve && reject){ // If a successful callback is passed , Failed callback originReplace.call(this,location,resolve,reject); }else{ originReplace.call(this,location,()=>{},()=>{}); } }stay index.js Rewriting in push|replace
版权声明
本文为[Write poetry for you@]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220549552897.html
边栏推荐
- Openinfra live | Kyushu yunhuang Shuquan was elected track chair and brought wonderful theme sharing
- 【无标题】金贝kdboxpro炫酷跑马灯颜值与实力并存
- Record a memory leak troubleshooting
- 7-4 到底是不是太胖了 (10 分)PTA
- JS reverse practice: analysis of Youdao translation interface
- Grafana influxdb simple script
- MySQL查询累计值的方法
- 第一款Avalon 1246-85T机箱大计算能力低功耗评测
- gradle打包tar、ZIP时,如何在最终的压缩包中包含一些空目录
- 有一份@九州云OFFER在等你
猜你喜欢
随机推荐
Pgbouncer最佳实践:系列三
Swing显示时间(点击一次显示一次)
金贝Lb1功耗参数实测
[required] 123
redis核心知识点总结(超详细)
ITS智能服务优秀企业年度榜单出炉,九州云荣获“2021信创运维10强”
第一款Avalon 1246-85T机箱大计算能力低功耗评测
Promise
Custom current limiting frame
Method of querying cumulative value in MySQL
SSH password free login
在PGConf.Asia-中文技术论坛,聆听腾讯云专家对数据库技术的深度理解
AQS和ReentrantLock源码解析
MySQL的InnoDB存储引擎
从proto生成go文件
Kyushu cloud was selected into China's top 500 Xinchuang in 2021
Link method of jasmine X4 ore pool
九州云获颁“2021年度企业”荣誉奖
马斯克与Twitter风波大戏
Mysql数据库的分区









