问题:在 Vue-Router
重复跳转同一路由时 Vue-Router
会抛出错误
解决方案:
- 在路由跳转前对重复路由进行截取判定
// this.$route.path 当前路由, item.path 要跳转的路由 if(this.$route.path !== item.path && !((this.$route.path == "/home") && (item.path == "/"))) { this.$router.push(item.path); }
- vue-router3.0 版本以上引入了
push
的 promise 语法,但是编程式路由没有解决路由重复的 promise 失败回调
// 使用 catch 捕获错误 this.$router.push(path).catch(()=>{})