Skip to content

Fix language switcher broken at root path - #26

Merged
noobnooc merged 1 commit into
mainfrom
claude/beautiful-panini-0d7e42
Apr 18, 2026
Merged

noobnooc merged 1 commit into
mainfrom
claude/beautiful-panini-0d7e42

Conversation

@noobnooc

Copy link
Copy Markdown
Member

Summary

  • Nav.tsx: Language switcher links were broken when the URL was /. usePathname() returns / at the root (because middleware rewrites / → /en without changing the browser URL), so pathname.replace("/en", "/de") found nothing to replace and all language options linked back to /. Fix: when pathname === "/", generate /${locale} directly.
  • layout.tsx: Moved OrganizationJsonLd and WebsiteJsonLd from <body> to an explicit <head> element — more semantically correct per HTML spec (JSON-LD in <head> is the conventional placement).

SEO note

The existing setup where / rewrites to /en (no redirect) is intentional for social crawlers. The canonical tag on the home page correctly points to /en, so Google consolidates signals — no duplicate content issue.

Test plan

  • Visit http://localhost:3000/ and open the language switcher — verify each language navigates to the correct localized root (e.g. /zh, /de)
  • Visit http://localhost:3000/en/docs and verify the language switcher still works as before
  • Check page source — confirm JSON-LD scripts appear inside <head>

🤖 Generated with Claude Code

- Nav.tsx: When pathname is "/", generate "/${locale}" directly instead
  of trying to replace "/${lang}" which doesn't exist in "/"
- layout.tsx: Move OrganizationJsonLd and WebsiteJsonLd from <body> to
  explicit <head> element, which is more semantically correct per HTML spec

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
echobell-one 874bc40 Commit Preview URL

Branch Preview URL
Apr 18 2026, 04:10 AM

@noobnooc
noobnooc merged commit 522c341 into main Apr 18, 2026
2 checks passed
@noobnooc
noobnooc deleted the claude/beautiful-panini-0d7e42 branch April 18, 2026 08:39
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