Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 18, 2026

Plan: Homepage Auto-Redirect to Current Language

Issue Understanding

The homepage (root /) should automatically redirect to the appropriate language version based on:

  • User's browser language preferences (Accept-Language header)
  • Fallback to default language if user's preferred language is not available

Root Cause

Without a root page.tsx file, Next.js doesn't recognize / as a valid route, so the middleware/proxy never gets invoked for homepage requests.

Solution Implemented

  1. Modified proxy.ts to add custom language detection for root path (commit 4b70311)
  2. Added app/page.tsx to ensure Next.js recognizes the root route (this commit)

The proxy intercepts / requests and redirects based on Accept-Language header:

  • zh-*/cn/docs
  • All other → /en/docs

Testing Results

✅ Chinese users (Accept-Language: zh-CN) → /cn/docs
✅ English users (Accept-Language: en-US) → /en/docs
✅ Users without language preference → /en/docs (default)

Changes Checklist

  • Modified proxy.ts to handle root path with custom language detection
  • Added app/page.tsx to enable middleware for homepage route
  • Verified build includes root route
  • Tested language detection with different Accept-Language headers
  • Confirmed redirects work correctly
Original prompt

首页应该可以自动跳转到可用的语言中的当前语言


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@vercel
Copy link

vercel bot commented Jan 18, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
docs Ready Ready Preview, Comment Jan 18, 2026 1:29am

Request Review

@github-actions
Copy link

🚀 Preview Deployment

This pull request will be automatically deployed to Vercel.

Preview Links

  • 📝 Documentation: Will be available once Vercel deployment completes
  • 🌍 Languages: English (/en/docs) and Chinese (/cn/docs)

Build Status

Check the CI workflow for build status and any errors.


Automated preview information for PR #47

@huangyiirene huangyiirene marked this pull request as ready for review January 18, 2026 01:02
@huangyiirene
Copy link
Collaborator

@copilot 为什么我没有跳转成功?

Copilot AI changed the title [WIP] Add automatic redirect to current language on homepage Add language detection to homepage redirect for zh→cn mapping Jan 18, 2026
Copilot AI requested a review from huangyiirene January 18, 2026 01:25
Copy link
Contributor Author

Copilot AI commented Jan 18, 2026

@copilot 为什么我没有跳转成功?

问题已修复!之前缺少根页面文件导致Next.js无法识别 / 路由,所以中间件没有被调用。

已添加 app/page.tsx 文件 (commit b9548d0),现在跳转功能正常工作:

  • 中文浏览器 (zh-CN) → 自动跳转到 /cn/docs
  • 英文浏览器 (en-US) → 自动跳转到 /en/docs

Homepage redirect working

@huangyiirene huangyiirene merged commit 760c625 into main Jan 18, 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.

2 participants