Commit 660406d3 by Jaxon

Merge branch 'feature/performance-overview' into 'SAAS+V5.8.2'

修复(路由): 忽略路由导航中的重复、取消等非致命错误

See merge request !12
2 parents a843b253 903a9355
......@@ -2,13 +2,38 @@ import Vue from "vue";
import Router from "vue-router";
import store from "@/store";
import routes from "./modules";
// hack router push callback
const originalPush = Router.prototype.push;
Router.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);
};
function isIgnorableNavigationError(err) {
if (!err)
return false;
const errorName = err.name || err._name || "";
const errorMessage = err.message || "";
return [
"NavigationDuplicated",
"NavigationCancelled",
].includes(errorName) || /Navigation (cancelled|duplicated|aborted)/i.test(errorMessage);
}
function wrapNavigationMethod(methodName) {
const originalMethod = Router.prototype[methodName];
Router.prototype[methodName] = function wrappedNavigation(location, onResolve, onReject) {
if (onResolve || onReject)
return originalMethod.call(this, location, onResolve, onReject);
return originalMethod.call(this, location).catch((err) => {
if (isIgnorableNavigationError(err))
return err;
return Promise.reject(err);
});
};
}
// hack router navigation callback
wrapNavigationMethod("push");
wrapNavigationMethod("replace");
Vue.use(Router);
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!