解决报错Navigation cancelled from“/.

2022-11-13  本文已影响0人  上海_前端_求内推

vue-router@3.0版本及以上回调形式已经改成promise api的形式了,返回的是一个promise,如果路由地址跳转相同, 且没有捕获到错误,控制台始终会出现如图所示的警告 (注:3.0以下版本则不会出现以下警告!!!,因路由回调问题…)

import VueRouter from 'vue-router'
Vue.use(VueRouter)
// 解决报错 此方法只针对VueRouter3.0以上
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}
上一篇 下一篇

猜你喜欢

热点阅读