SEO & Meta Head
Relevant source files
The following files were used as context for generating this wiki page:
The SEO & Meta Head system provides automated generation of internationalization metadata for Nuxt applications. It ensures that localized pages correctly communicate their language, region, and relationship to other language versions to search engines and social media crawlers.
The system manages critical SEO tags including hreflang alternates, canonical URLs, og:locale tags, and the lang attribute for the <html> element. It prioritizes performance and build-time efficiency, serving as a lightweight alternative to traditional i18n SEO solutions.
Sources: README.md:14-18, src/runtime/plugins/02.meta.ts:60-80
Architecture and Integration
The SEO system integrates with Nuxt through a dedicated plugin that coordinates between various composables and the Nuxt useHead interface.
Core Components
useLocaleHead: Generates the primary metadata object, including SEO and direction attributes.useI18nHead: Allows developers to define per-page i18n SEO overrides.02.meta.tsPlugin: Resolves the base URL, watches for route or locale changes, and merges metadata before injecting it into the page head.
Sources: src/runtime/plugins/02.meta.ts:40-47, packages/utils/CHANGELOG.md:105-107
SEO Generation Flow
The following diagram illustrates how the system processes and merges metadata during the application lifecycle:
The plugin monitors route paths, route names, and locale state to trigger meta refreshes, ensuring tags remain accurate during client-side navigation.
Sources: src/runtime/plugins/02.meta.ts:98-112
Base URL Resolution
The system determines the base URL for canonical and og:url tags using a hierarchical resolution strategy. This ensures absolute URLs are generated even when explicit configuration is missing.
Resolution Logic
metaBaseUrl: Uses the explicitly configured URL in the module options if present.site.url: Attempts to read from@nuxtjs/seoornuxt-site-configif installed.- Request Origin: Falls back to the current request URL origin, respecting proxy headers if
metaTrustForwardedHostormetaTrustForwardedProtoare enabled.
Sources: src/runtime/plugins/02.meta.ts:10-38, test/nuxt-seo.spec.ts:86-90
Sources: src/runtime/plugins/02.meta.ts:25-36
Meta Attributes and Tags
The system generates a standard set of tags required for international SEO compliance.
| Tag Category | Key Attributes / Details | Implementation Detail |
|---|---|---|
| Hreflang | rel="alternate", hreflang, href | Emitted from ISO codes, includes x-default. |
| Canonical | rel="canonical", href | Uses resolved Base URL + localized path. |
| Open Graph | og:locale, og:url | Format: en_US (underscore) for og:locale. |
| HTML Attributes | lang, dir | lang uses ISO; dir supports ltr and rtl. |
| Sources: src/runtime/plugins/02.meta.ts:65-70, test/nuxt-seo.spec.ts:54-65, scripts/src/commands/smoke-verify.ts:121-125 |
Hreflang and Alternates
The system generates alternate links for all configured locales. It includes an x-default entry, which typically points to the default locale version. Recent updates ensure that hreflang values are derived from the locale's ISO code rather than the routing code.
Sources: packages/utils/CHANGELOG.md:46-47, test/nuxt-seo.spec.ts:54-60
Social Media Metadata
og:locale tags are automatically formatted to use underscores (e.g., en_US) to comply with social platform requirements. The og:url reflects the absolute localized path of the current page.
Sources: test/nuxt-seo.spec.ts:98-102, packages/utils/CHANGELOG.md:112-113
Configuration and Overrides
Metadata generation can be controlled globally or on a per-route basis.
Disabling Metadata
Metadata generation is skipped if:
- The global
metaoption is false. i18n.disableMetais set to true in specific environments (like SSG).- The current route matches
routeDisableMetapatterns defined in the configuration.
Sources: packages/vitepress/tests/playground-ssg.test.ts:60-68, src/runtime/plugins/02.meta.ts:75-78
Page-Level Overrides
Using the useI18nHead composable, developers can inject specific meta objects that are merged with the automatically generated ones. This is useful for providing custom descriptions, titles, or social images that should accompany the localized routing tags.
Sources: src/runtime/plugins/02.meta.ts:43, packages/utils/CHANGELOG.md:105-107
Summary
The SEO & Meta Head module automates the complex task of managing localized metadata in Nuxt. By resolving base URLs from multiple sources and merging page-specific overrides with automated hreflang and Open Graph tags, it ensures that applications are search-engine friendly with minimal configuration. The integration with the Nuxt lifecycle guarantees that metadata is correctly rendered during SSR and updated during client-side navigation.