未捕获(在承诺)错误:导航取消从“/”到“/home”与一个新的导航。

文章描述:

Vue报错:Uncaught (in promise) Error: Navigation cancelled from “/” to “/home” with a new navigation. at createRouterError,解决方法

解决方法如下:

在路由器中进行配置:router/index.js

const originalPush = VueRouter.prototype.push;
const originalReplace = VueRouter.prototype.replace;
//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);
};
//replace
VueRouter.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);
};

 

发布时间:2022/07/27

发表评论