1.固定vue-router版本到3.0.7以下。
2.禁止全局路由错误处理打印,这个也是vue-router开发者给出的解决方案:
import Router from 'vue-router' const originalPush = Router.prototype.push Router.prototype.push = function push(location, onResolve, onReject) { if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject) return originalPush.call(this, location).catch(err => err) }
3.为每个router.push增加回调函数:
router.push('/location').catch(err => {err})