您当前的位置: 首页 >  ide

暂无认证

  • 0浏览

    0关注

    92582博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

vue重复点击导航时,控制台出现报错、Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to

发布时间:2022-05-01 00:12:02 ,浏览量:0

目录
  • 1、方案一
  • 2、方案二
  • 3、方案三
  • 4、方案四
  • 5、总结
  • 6、相关链接
1、方案一

在router文件夹下的index.js文件中添加如下代码。

Vue.use(Router) const router = new Router({ routes }); // 添加的的代码 const VueRouterPush = Router.prototype.push; Router.prototype.push = function push (to) { return VueRouterPush.call(this, to).catch(err => err); }; // 添加的的代码 
2、方案二

在跳转时,判断跳转路由和当前路由是否一致,避免重复跳转产生问题。

toMenu (item) { if (this.$route.path !== item.url) { this.$router.push({ path: item.url }); } } 
3、方案三

使用catch方法捕获router.push异常。

this.$router.push(route).catch(err => { console.log('输出报错', err); }); 
4、方案四

降低路由版本。

卸载原来的版本

npm uninstall vue-router

安装指定版本

npm install vue-router@3.0.6 
5、总结

方案一亲测多次都没有用,最靠谱的是方案四,其他方案没测。

6、相关链接

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

关注
打赏
1653961664
查看更多评论
立即登录/注册

微信扫码登录

0.4393s