useLocaleHead
useLocaleHead() builds the i18n head tags for the current route: lang and dir on <html>, a canonical link, hreflang alternates with x-default, og:url, og:locale and og:locale:alternate. Use it when you set meta: false and manage useHead yourself; with meta: true the module already registers these tags, and per-page changes go through useI18nHead.
Signature
useLocaleHead(options: UseLocaleHeadOptions): { build: () => LocaleHead; metaObject: Ref<{ htmlAttrs: { dir?: "ltr" | "rtl" | "auto"; lang?: string; [key: string]: string | undefined }; link: ({ href: string; rel: "canonical"; [key: string]: string | undefined } | { href: string; hreflang: string; rel: "alternate"; [key: string]: string | undefined })[]; meta: { content: string; property: string; [key: string]: string }[] }, LocaleHead | { htmlAttrs: { dir?: "ltr" | "rtl" | "auto"; lang?: string; [key: string]: string | undefined }; link: ({ href: string; rel: "canonical"; [key: string]: string | undefined } | { href: string; hreflang: string; rel: "alternate"; [key: string]: string | undefined })[]; meta: { content: string; property: string; [key: string]: string }[] }>; updateMeta: () => void }
The SEO head tags for the current route: hreflang alternates for every locale plus
x-default, a canonical link, og:locale, and lang/dir on <html>.
Only needed when meta is disabled or the defaults need adjusting — with meta: true
the module registers the same tags itself.
Returns — metaObject, a ref holding the head object ready to pass to useHead; updateMeta refreshes it; build computes the head object from the current route (reactive when read in a getter, e.g. useHead(() => build()))
const { metaObject } = useLocaleHead({ addSeoAttributes: true })
useHead(metaObject)
Options
| Option | Default | Description |
|---|---|---|
addDirAttribute | true | Set dir on <html> from the locale's dir ('auto' when it has none). |
identifierAttribute | 'id' | Attribute that keys each tag (i18n-can, i18n-og, i18n-alternate-<hreflang>, …), so updates replace tags instead of adding them. |
addSeoAttributes | true | Emit canonical, hreflang and og: tags. false keeps only htmlAttrs. |
baseUrl | '/' | Origin joined to every URL. Keep '/' for relative URLs; pass 'https://example.com' for absolute ones. |
autoUpdate | true | Rebuild metaObject when the route or the i18n-locale state changes. |
What it emits
- Nothing on a route with no match (404) or with
disableMetafor the active locale. - Canonical and
og:url:$switchLocalePath(<active locale>), query reduced tocanonicalQueryWhitelist,trailingSlashapplied. hreflang: one link per enabled locale the page exists in,hreflang = iso || code, skipping locales withseo: false; withhreflangBaseLanguage: truethe first regional locale of a language also emits its bare-language tag. None underno_prefix.x-default: the default locale's URL, unless the strategy isno_prefix, the default locale hasseo: false, or the page does not exist in it.og:locale/og:locale:alternate: from the locale'sog, or itsisoconverted (en-US→en_US); skipped with a dev warning when neither works.
Example
// app.vue, with i18n.meta: false
const { metaObject } = useLocaleHead({ baseUrl: 'https://example.com' })
useHead(metaObject)
build() returns the same object without the ref: useHead(() => build()) stays reactive without a watcher.