Blame view

src/router/guard/messageGuard.ts 629 Bytes
vben authored
1
2
import type { Router } from 'vue-router';
import { Modal, notification } from 'ant-design-vue';
3
import projectSetting from '/@/settings/projectSetting';
vben authored
4
5
import { warn } from '/@/utils/log';
vben authored
6
7
8
9
/**
 * Used to close the message instance when the route is switched
 * @param router
 */
vben authored
10
export function createMessageGuard(router: Router) {
11
  const { closeMessageOnSwitch } = projectSetting;
vben authored
12
13
14
15
16
17
18
19
20
21
22
23
24

  router.beforeEach(async () => {
    try {
      if (closeMessageOnSwitch) {
        Modal.destroyAll();
        notification.destroy();
      }
    } catch (error) {
      warn('message guard error:' + error);
    }
    return true;
  });
}