Tag Archives: Vue Uncaught (in promise) Error

Vue Uncaught (in promise) Error: Navigation cancelled from “/home“ to “/login“ with a new navigation

1. Initialize the entry item, redirect to the login page after the login expires, and the routing error is reported

import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)

//Solve the situation that programmatic routing to the same address will report an error
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);
};