create-iking-admin
Version:
金合技术中台脚手架
36 lines (29 loc) • 1.05 kB
text/typescript
import { useGlobSetting } from '@/global/hooks/setting';
import { useI18n } from '@/global/hooks/web/useI18n';
import { useLocaleStore } from '@/global/store/modules/locale';
import { useTitle as usePageTitle } from '@vueuse/core';
import { unref, watch } from 'vue';
import { useRouter } from 'vue-router';
import { REDIRECT_NAME } from '@/mainApp/router/constant';
/**
* Listening to page changes and dynamically changing site titles
*/
export function useTitle() {
const { title } = useGlobSetting();
const { t } = useI18n();
const { currentRoute } = useRouter();
const localeStore = useLocaleStore();
const pageTitle = usePageTitle();
watch(
[() => currentRoute.value.path, () => localeStore.getLocale],
() => {
const route = unref(currentRoute);
if (route.name === REDIRECT_NAME) {
return;
}
const tTitle = t(route?.meta?.title as string);
pageTitle.value = tTitle ? ` ${tTitle} - ${title} ` : `${title}`;
},
{ immediate: true },
);
}