在router文件夹内的index.js文件内加入以下内容
//加入的内容
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
return originalPush.call(this, location).catch(err => err)
}
import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)
const routes = [
{path:'/',redirect:'/home'},
{path:"/home",component:()=>import("../views/Home")},
]
const router = new VueRouter({
routes
})
//需要添加内容
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
return originalPush.call(this, location).catch(err => err)
}
export default router