Blame view

src/router/guard/pageGuard.ts 450 Bytes
vben authored
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import type { Router } from 'vue-router';
import { setLastChangeTab } from '/@/logics/mitt/tabChange';

export function createPageGuard(router: Router) {
  const loadedPageMap = new Map<string, boolean>();

  router.beforeEach(async (to) => {
    to.meta.loaded = !!loadedPageMap.get(to.path);
    // Notify routing changes
    setLastChangeTab(to);

    return true;
  });

  router.afterEach((to) => {
    loadedPageMap.set(to.path, true);
  });
}