在使用vue-router时,脚手架vue/cli的4.0中,若重复点击按钮,跳转路由链接报错处理
控制台报错如下:
NavigationDuplicated {_name: "NavigationDuplicated", name: "NavigationDuplicated", message: "Navigating to current location ("/users") is not allowed" ...... }
需要在路由配置文件中添加如下代码:
Vue.use(VueRouter)
// 在路由跳转的时候同一个路由多次添加是不被允许的
// 在vue脚手架的 4.0 的版本需要加入如下代码
const VueRouterPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(to) {
return VueRouterPush.call(this, to).catch(err => err)
}