vue导航重复:避免冗余导航到当前位置问题解决

1,406 阅读41分钟

报错信息:Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to current location: "/home".

import VueRouter from 'vue-router'

Vue.use(VueRouter)

//获取原型对象上的push函数

const originalPush = VueRouter.prototype.push

//修改原型对象中的push方法

VueRouter.prototype.push = function push(location) {

return originalPush.call(this, location).catch(err => err)

}