发布时间:2025-12-09 11:52:07 浏览次数:1
最近在弄一个vue项目时碰到这么一个报错,查了下资料,记录一下:
这个错误是vue-router的内部错误,是因为没有进行catch处理,导致的编程式导航跳转问题,往同一个地址跳转时,会报错。
解决方法如下:在路由文件中进行配置:router/index.jsimport Vue from 'vue'import Router from 'vue-router'Vue.use(Router)// 解决报错const originalPush = Router.prototype.pushconst originalReplace = Router.prototype.replace// pushRouter.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)}// replaceRouter.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)}我暂时用此方法解决了,有更好的欢迎讨论…
158911.html