useLocaleSeo

Inject hreflang alternate links, x-default and og:locale on multilingual sites so search engines can tell the language versions apart. The layer's app.vue already calls it globally; call it yourself only when you rewrite app.vue.

useLocaleSeo() only takes effect when @nuxtjs/i18n is enabled with at least two valid locales; otherwise it returns without injecting anything.

Usage

app/app.vue
<script setup lang="ts">
await useDocsShell()
useLocaleSeo()
</script>

Signature

function useLocaleSeo(): void

Injected Tags

TagValue
<link rel="alternate" hreflang="{code}">One per valid locale; href is site.url plus the current page's path in that locale
<link rel="alternate" hreflang="x-default">Points to the current page in the first locale of the list
<meta property="og:locale">Current locale code with - replaced by _, such as zh_CN

Notes

  • Links are absolute, so site.url must be set in nuxt.config.
  • No alternate is generated for a locale where the page does not exist (switchLocalePath returns an empty string).

Changelog

No recent changes
Copyright © 2024 - 2026