You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
950 B
34 lines
950 B
import { unref, watch } from 'vue' |
|
import { useTitle as usePageTitle } from '@vueuse/core' |
|
import { useRouter } from 'vue-router' |
|
import { useI18n } from '@/hooks/web/useI18n' |
|
import { useGlobSetting } from '@/hooks/setting' |
|
import { useLocaleStore } from '@/store/modules/locale' |
|
|
|
import { REDIRECT_NAME } from '@/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) |
|
pageTitle.value = tTitle ? ` ${tTitle} - ${title} ` : `${title}` |
|
}, |
|
{ immediate: true }, |
|
) |
|
}
|
|
|