第一种方法:
在 router.js 的配置文件中,Vue.use(VueRouter)下面加上如下代码:
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
return originalPush.call(this, location).catch(err => err)
}
第二种方法:
将 vue-router 的版本降到 3.0
yarn add vue-router@3.0
以上两种方法都可以解决报错的问题.