在点击一个路由跳转时,点击几次后浏览器就出现报错
Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to current location
解决方法
Vue.use(VueRouter)
const VueRouterPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (to) {
return VueRouterPush.call(this, to).catch(err => err)
}
//加上这段代码就解决了
当在Vue应用中使用Vue Router进行页面跳转时,可能会遇到NavigationDuplicated错误。该错误表明尝试进行到已当前所在的位置。通过覆盖VueRouter.prototype.push方法并捕获错误,可以避免这个问题。只需添加一段代码,就能确保即使重复导航也不会抛出错误。
2528

被折叠的 条评论
为什么被折叠?



