VUE-Router之解决 Navigating to current location (XXX) is not allowed

绝地灬酷狼 2023-02-12 08:28 98阅读 0赞

VUE-Router之解决 Navigating to current location (“/index/list2”) is not allowed

错误代码:

  1. NavigationDuplicated {
  2. _name: "NavigationDuplicated",
  3. name: "NavigationDuplicated",
  4. message: "Navigating to current location ("/index/list2") is not allowed",
  5. stack: "Error↵ at new NavigationDuplicated (webpack-int…al:///./node_modules/vue/dist/vue.esm.js:1862:26)"
  6. }

操作:
在vue项目中点击两次路由切换

原因:
多次点击跳转同一个路由是不被允许的

解决方案(两种):
1.降低版本:切换版本回3.0版本
2.重写规则:在你引了vue-router的js文件里加上如下代码即可(我的在index.js文件)

  1. import Vue from 'vue' //如果已引用,不需要重复引用
  2. import Router from 'vue-router'; //如果已引用,不需要重复引用
  3. Vue.use(Router) //如果已引用,不需要重复引用
  4. //push
  5. const VueRouterPush = Router.prototype.push
  6. Router.prototype.push = function push (to) {
  7. return VueRouterPush.call(this, to).catch(err => err)
  8. }
  9. //replace
  10. const VueRouterReplace = Router.prototype.replace
  11. Router.prototype.replace = function replace (to) {
  12. return VueRouterReplace.call(this, to).catch(err => err)
  13. }

打赏

谢谢对小女子的关注,我会坚持更新我所遇到的bug及解决方案。要觉得小女子写得还行,可以打赏些小费的哟~
在这里插入图片描述
在这里插入图片描述

发表评论

表情:
评论列表 (有 0 条评论,98人围观)

还没有评论,来说两句吧...

相关阅读