perf: optimize tab switching speed

This commit is contained in:
vben
2020-11-10 21:58:19 +08:00
parent 439291746f
commit 4baf90a5c8
9 changed files with 192 additions and 47 deletions

View File

@@ -12,6 +12,8 @@ import { getIsOpenTab, setCurrentTo } from '/@/utils/helper/routeHelper';
import { setTitle } from '/@/utils/browser';
import { AxiosCanceler } from '/@/utils/http/axios/axiosCancel';
import { tabStore } from '/@/store/modules/tab';
const { projectSetting, globSetting } = useSetting();
export function createGuard(router: Router) {
const { openNProgress, closeMessageOnSwitch, removeAllHttpPending } = projectSetting;
@@ -20,8 +22,21 @@ export function createGuard(router: Router) {
axiosCanceler = new AxiosCanceler();
}
router.beforeEach(async (to) => {
// Determine whether the tab has been opened
const isOpen = getIsOpenTab(to.fullPath);
to.meta.inTab = isOpen;
// Notify routing changes
const { fullPath, path, query, params, name, meta } = to;
tabStore.commitLastChangeRouteState({
fullPath,
path,
query,
params,
name,
meta,
} as any);
try {
if (closeMessageOnSwitch) {
Modal.destroyAll();