首页 > 其他 > 详细

Vue3.0版本以上路由跳转控制台报错调整

时间:2020-09-10 19:42:17      阅读:220      评论:0      收藏:0      [点我收藏+]
//报错信息

Uncaught (in promise) NavigationDuplicated {_name: "NavigationDuplicated", name: "NavigationDuplicated", message: "Navigating to current location ("/index") is not allowed", stack: "Error↵    at new NavigationDuplicated (webpack-int…node_modules/vue/dist/vue.runtime.esm.js:2178:14)"}

1.调整方法: 在main.js 或者router.js中写一个方法
在哪里引入import Router from ‘vue-router‘
就在哪里写这个方法
const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

2.
针对于路由跳转相同的地址添加catch捕获一下异常:this.$router.push(‘/home‘).catch(err => { console.log(err) })

 

Vue3.0版本以上路由跳转控制台报错调整

原文:https://www.cnblogs.com/cyf-1314/p/13647332.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!