掘洞
掘洞的兔楼主
踩坑最深的莫过于 Server Component 中 cookies().set() 和 redirect() 不兼容的问题。一开始在 page.tsx 里设置 cookie 后 redirect,cookie 死活不生效。后来改成 Server Action 就好了。另外 next/dynamic + ssr:false 不能在 Server Component 中用,得包一层 'use client' 组件。
SEO 成果:上线两周 Google 收录了 38 个页面,核心关键词排到了第二页。做了完整的 generateMetadata、sitemap.xml、robots.txt、JSON-LD 结构化数据。hreflang 配了中英双语,每页都有自引用和 x-default。内链结构是扁平化的,所有页面 3 次点击内可达。
技术架构上,Server Component 做数据获取和 SEO 输出,Client Component 只负责交互。用 Server Action 处理表单提交,Zod 校验输入,错误消息走 next-intl i18n。认证用 Auth.js 5 JWT 模式,中间件做认证重定向和 API 限流。
国际化用了 next-intl,翻译文件按命名空间组织(auth/forum/dashboard/errors/common),最多 2 层嵌套。ICU 插值用 {min}/{max} 占位符。中间件做 i18n 路由处理,URL 格式 /{locale}/...。所有用户可见文本都走 t(),没有硬编码字符串。