自己写tabbar组件时重复点击按钮报错如下
Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to current location:
"/shopcart"
解决方式:抛出异常
- 可以写在点击按钮处
itemClick(){
this.$router.push(this.path).catch(err=>err)
}
- 也可以写在router/index.js中下面这段代码
import Router from 'vue-router'
// 解决重复点击路由报错的BUG
const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
return originalPush.call(this, location).catch((err) => err)
}
注意此处我的跳转路由的方式是push()
,其他的方式将push替换即可