import { useTitle } from '@vueuse/core';
import type { Router } from 'vue-router';
import { $t } from '@/locales';

export function createDocumentTitleGuard(router: Router) {
  router.afterEach(to => {
    console.log('after router ===', to)


    // Hack 临时处理 (不知名原因)
    if(to.hash.includes('#f')) {
      window.location.href ='/demo';
    }


    const { i18nKey, title } = to.meta;

    const documentTitle = i18nKey ? $t(i18nKey) : title;

    useTitle(documentTitle);
  });
}
