简体   繁体   English

Next.js 带子域的域路由

[英]Next.js domain routing with sub-domains

I am trying to translate my Next app based on the current sub-domain.我正在尝试根据当前子域翻译我的 Next 应用程序。 For example, I would like en.hello.com to be in English, and it.hello.com to be in Italian.例如,我希望en.hello.com为英文,而it.hello.com为意大利文。

I am trying to achieve that using Next's domain routing , but apparently, that is not meant to be used with sub-domains but rather with top-level domains like hello.en and hello.it for English and Italian for example.我正在尝试使用 Next 的域路由来实现这一点,但显然,这并不意味着与子域一起使用,而是与顶级域一起使用,例如hello.enhello.it用于英语和意大利语。

Here is my next.config.js :这是我的next.config.js

module.exports = {
  i18n: {
    locales: ["en", "it"],
    defaultLocale: "en",

    domains: [
      {
        domain: "en.hello.com",
        defaultLocale: "en",
      },
      {
        domain: "it.hello.com",
        defaultLocale: "it",
      },
    ],
  },
};

These settings fail to map en.hello.com to English and it.hello.com to Italian.这些设置无法将 map en.hello.com为英语,将it.hello.com为意大利语。

Can anybody explain why that is and how can I achieve sub-domain routing in Next?谁能解释为什么会这样以及如何在 Next 中实现子域路由?

What you're trying to do does not seem to be a supported feature.您尝试执行的操作似乎不受支持。 Per your own provided documentation , you can have either a top level locale domain such as .it or a sub-path such as /it .根据您自己提供的文档,您可以拥有顶级语言环境域(例如.it )或子路径(例如/it )。 Now i'm not sure why you want a subdomain when majority of websites on the inte.net are opting for the sub-path.现在我不确定为什么在 inte.net 上的大多数网站都选择子路径时你想要一个子域。 If you choose sub-path, then by providing the Accept-Language: it;q=0.9 header user will be redirected automatically.如果您选择子路径,则通过提供Accept-Language: it;q=0.9 header 用户将被自动重定向。

Alternative选择

If you're unable to utilize either of supported features, then your only other option is to create custom servers .如果您无法使用任一受支持的功能,那么您唯一的其他选择是创建自定义服务器 This comes with a lot more work and you'll also lose the ability to deploy to vercel platform.这带来了更多的工作,您还将失去部署到 Vercel 平台的能力。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM