当前位置: 首页 > Web前端 > vue.js

vue-router报错:NavigationDuplicated

时间:2023-04-01 02:13:16 vue.js

版本:3.1.x报错原因:使用push()和replace()导航时,无法重复导航到当前路由。解决方法:方法一:在文件中定义路由router/index.jsconstoriginalPush=VueRouter.prototype.pushVueRouter.prototype.push=functionpush(location){returnoriginalPush.call(this,location).catch(err=>err)}constoriginalReplace=VueRouter.prototype.replaceVueRouter.prototype.repalce=functionreplace(location){returnoriginalReplace.call(this,location).catch(err=>err)}方法二:调用push()后,替换()method,catchthis.$router.replace(this.path).catch(err=>err)解释:第一个方法似乎对replace()没有影响。