在vue项目中路由跳转过程中浏览器会报Avoided redundant navigation to current location 这个错误,解决方法:在路由文件里添加这一句可解决报错问题
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: '/about',
name: 'About',
component: () => import('../views/About.vue')
}
]
const originalPush = VueRouter.prototype.push
VueRouter.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)
}
const router = new VueRouter({
routes
})
export default router