Centralize i18n canonical/hreflang generation and fix blog slug handling#134
Merged
Merged
Conversation
…04 page Blog posts use a different slug per language, so the language switcher naively reused the current slug and produced a 404 when switching languages. Publish the per-locale slugs via useSetI18nParams so switchLocalePath / <SwitchLocalePathLink> resolve the correct localized URL, and switch LanguageSelector to <SwitchLocalePathLink> to avoid stale SSR links. A missing or unreleased article (and any unmatched route) now raises a fatal 404 instead of silently rendering an empty page, surfaced through a new localized error.vue. https://claude.ai/code/session_01QsCtq62jJ1pfbxJfMKFm1y
Search Console reported duplicate / conflicting canonical signals
("Google chose a different canonical"). Canonical and hreflang were
hand-rolled in three places with diverging values: usePageSeo derived
the canonical from route.fullPath (leaking utm/fbclid query params into
infinite canonical variants), useBlogContent emitted its own
frontmatter-driven set, and useSetI18nParams additionally injected the
i18n SEO set on blog pages.
Consolidate on @nuxtjs/i18n as the single source of truth: spread
useLocaleHead({ seo }) app-wide in the default layout so every page
emits exactly one self-referential canonical plus reciprocal
de/en/x-default hreflang. Blog posts feed their translated slugs through
useSetI18nParams, so the i18n-generated tags use the correct
per-language URL. usePageSeo / useBlogContent no longer emit their own
canonical, alternate or og:locale tags. i18n baseUrl is pinned to the
production domain so the tags Google sees are always the real URLs.
https://claude.ai/code/session_01QsCtq62jJ1pfbxJfMKFm1y
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR refactors SEO tag generation to use @nuxtjs/i18n's built-in canonical and hreflang support instead of hand-rolling duplicate logic across multiple composables. It also fixes blog article language switching by publishing per-locale slugs through
useSetI18nParams, and adds proper error page handling for missing/unreleased articles.Key Changes
layouts/default.vueusinguseLocaleHead()from @nuxtjs/i18n, eliminating duplicate link tag generation inusePageSeoanduseBlogArticleuseSetI18nParams()integration inuseBlogArticleto publish translated slugs per locale, enabling<SwitchLocalePathLink>to resolve correct localized URLs instead of naively reusing the current slugslugFromUrl()andlocaleCodeFromHreflang()helpers to extract and map slugs from front-matteralternatesandtranslationKeycross-collection lookupserror.vuecomponent with proper 404/generic error states; changeduseBlogArticleto return a marker instead of throwing, then raise a fatal error after data resolves for reliable SSR error page renderinguseBlogArticleasync and awaited in page component to ensure data resolves before renderingLanguageSelector.vueto use<SwitchLocalePathLink>instead of manualsetLocale+navigateTo, delegating navigation to the i18n component which now handles translated slugsnuxt.config.tsbaseUrl to production domain so SEO tags always reflect real URLs across all environmentsImplementation Details
alternateLanguagesandheadLinkscomputed refs fromuseBlogArticle— these are now generated app-wide by @nuxtjs/i18npublishLocaleParams()function inuseBlogArticleupdates i18n's internal route params whenever article translations are resolved, making the canonical/hreflang tags automatically reflect the correct localized slugsresolveHreflang()andHeadLinktype; simplifiedusePageSeoto only handle page-specific robots/keywords metahttps://claude.ai/code/session_01QsCtq62jJ1pfbxJfMKFm1y