titleGuard.ts 493 B

123456789101112131415161718
  1. import type { Router } from 'vue-router';
  2. import { useGlobSetting } from '/@/hooks/setting';
  3. import { setTitle } from '/@/utils';
  4. import { useI18n } from '/@/hooks/web/useI18n';
  5. import { REDIRECT_NAME } from '/@/router/constant';
  6. const globSetting = useGlobSetting();
  7. export function createTitleGuard(router: Router) {
  8. router.afterEach(async (to) => {
  9. const { t } = useI18n();
  10. to.name !== REDIRECT_NAME && setTitle(t(to.meta.title), globSetting.title);
  11. return true;
  12. });
  13. }