在vue项目中经常会遇到重复跳转报错的问题
vue中使用router.push或者router.replace频繁跳转会遇到报错
导致路由重复报错----Avoided redundant navigation to current location: “/about”.
解决方法:
如果是push,在路由中写入一下代码:
//解决push
const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
return originalPush.call(this, location).catch(err => err)
}
如果是replace
//解决 replace
const originalReplace = Router.prototype.replace
Router.prototype.replace = function push(location, onResolve, onReject) {
if (onResolve || onReject) return originalReplace.call(this, location, onResolve, onReject)
return originalReplace.call(this, location).catch(err => err)
}