Blame view

src/router/guard/progressGuard.ts 622 Bytes
陈文彬 authored
1
2
import type { Router } from 'vue-router';
vben authored
3
4
import { useTransitionSetting } from '/@/hooks/setting/useTransitionSetting';
陈文彬 authored
5
6
import NProgress from 'nprogress';
import 'nprogress/nprogress.css';
vben authored
7
8
9
import { unref } from 'vue';

const { getOpenNProgress } = useTransitionSetting();
陈文彬 authored
10
11

export function createProgressGuard(router: Router) {
12
  router.beforeEach(async (to) => {
vben authored
13
14
    if (to.meta.loaded) return true;
    unref(getOpenNProgress) && NProgress.start();
陈文彬 authored
15
16
    return true;
  });
vben authored
17
18
  router.afterEach(async (to) => {
vben authored
19
20
    if (to.meta.loaded) return true;
    unref(getOpenNProgress) && NProgress.done();
陈文彬 authored
21
22
23
    return true;
  });
}