Skip to content

Keep language switcher on the same page when switching#46

Merged
Marv51 merged 1 commit into
mainfrom
fix-language-switcher-preserve-page
Jul 12, 2026
Merged

Keep language switcher on the same page when switching#46
Marv51 merged 1 commit into
mainfrom
fix-language-switcher-preserve-page

Conversation

@Marv51

@Marv51 Marv51 commented Jul 12, 2026

Copy link
Copy Markdown
Owner

What

The nav language links pointed unconditionally at / and /de. Switching language on the imprint page therefore dumped you back on the homepage instead of the equivalent /de/impressum or /en/imprint.

This extracts a shared LangSwitcher component that reads the current location and links each language to the equivalent page in the other tree, preserving your place.

Why it's tidy

The en/de page pairs are derived from the existing PAGES record in seo-links.ts — already the single source of truth for canonical/hreflang <link>s and the sitemap. A new bilingual page added there now flows into the switcher too, with no duplicated path constants.

Notes for reviewer

  • Both layout.tsx and layout-de.tsx now render <LangSwitcher /> instead of duplicating the hard-coded links.
  • NavLink uses end so the active-highlight (lang-left/lang-right) reflects the current language exactly on each page.
  • Verified against the prerendered output for all four routes (/, /de, /en/imprint, /de/impressum): each language links to its same-page equivalent with the correct active state. Typecheck passes.

🤖 Generated with Claude Code

The nav language links pointed unconditionally at / and /de, so
switching language on the imprint page dumped you back on the homepage
instead of the equivalent /de/impressum or /en/imprint.

Extract a shared LangSwitcher component that reads the current location
and links each language to the equivalent page in the other tree. The
en/de page pairs are derived from the existing PAGES record in
seo-links.ts, so it stays a single source of truth alongside the
canonical/hreflang links and the sitemap — a new bilingual page added
there now flows into the switcher too.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@Marv51
Marv51 merged commit 0292a39 into main Jul 12, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant