解决vue路由跳转报错,Navigation cancelled ……to with a new navigation

发布时间:2025-12-09 12:05:28 浏览次数:2

vue跳转路由报错:

解决 Uncaught (in promise) Error: Navigation cancelled from “/Search#1608911018888” to “/Search#1608911019245” with a new navigation.

1、报错原因:

这个错误是vue-router内部错误,没有进行catch处理,导致的编程式导航跳转问题,往同一地址跳转时会报错的情况。

在升级了Vue-Router版本到到3.1.0及以上之后,页面在跳转路由控制台会报Uncaught (in promise)的问题,在3.1.0版本里面新增功能:push和replace方法会返回一个promise, 你可能在控制台看到未捕获的异常。

// pushVueRouter.prototype.push = function push (location, onResolve, onReject) {  // if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)  return originalPush.call(this, location).catch(err => {return;})}// replaceVueRouter.prototype.replace = function replace (location, onResolve, onReject) {  // if (onResolve || onReject) return originalReplace.call(this, location, onResolve, onReject)  return originalReplace.call(this, location).catch(err => err)}
navigationcancelled
需要做网站?需要网络推广?欢迎咨询客户经理 13272073477