首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Next.js next-i18next总是路由到EN

Next.js next-i18next总是路由到EN
EN

Stack Overflow用户
提问于 2020-11-13 22:32:14
回答 2查看 490关注 0票数 0

我有一个简单的项目,应该与英语和荷兰语(默认)的工作。我复制了原始示例中的所有内容,但不知何故,它并没有像预期的那样工作。

即使我有browserLanguageDetection: false,它也迫使我使用/en端点。

我想在/上显示NL文本,但目前无法显示。

你能检查一下沙箱,告诉我这里出了什么问题吗?

https://codesandbox.io/s/pensive-galileo-zifjm?file=/pages/index.js

EN

回答 2

Stack Overflow用户

发布于 2020-11-14 06:59:21

重要的是要知道,在Next.js中,第一次加载总是在服务器端完成。在i18n.js中,您定义了browserLanguageDetection: false,但没有定义serverLanguageDetection: false,这就是为什么您总是被重定向到/en

在索引页中,将此行export default withTranslation('common')(IndexPage);替换为以下export default withTranslation(['common'])(IndexPage);,以避免此warning

票数 1
EN

Stack Overflow用户

发布于 2021-05-03 20:03:42

文档中有解决方案。这就是:https://nextjs.org/docs/advanced-features/i18n-routing

看起来不错。

代码语言:javascript
复制
i18n: {
 defaultLocale: 'en',
 locales: ['en'],
 
 localeDetection: false, // Important!

 domains: [
  {
   domain: 'example.com', // <-
   defaultLocale: 'en' // This locale will be appeared at the exact above domain.
  },
  {
   // 2nd locale goes here in the same way.
  }
 ]
}

我希望这会有帮助。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64822738

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档