简体   繁体   English

Nextjs 继续使用双重语言环境重定向

[英]Nextjs keep redirecting with double locale

We trying to redirect client if client's wish locale is not provided in the page.如果页面中没有提供客户希望的语言环境,我们会尝试重定向客户。

So i added所以我加了

    redirect: !isPossibleLang
      ? {
          destination: `/${locale}/main/${id}`,
          statusCode: 301,
        }
      : undefined,

In the return of getStaticProps.在 getStaticProps 的返回中。

But next.js keep adding current language in the url.但是 next.js 继续在 url 中添加当前语言。
like /ko/main/ID => /en/ko/main/ID/ko/main/ID => /en/ko/main/ID

My next.config.js我的 next.config.js


module.exports = {
  reactStrictMode: true,
  i18n: {
    locales: ['en', 'ko'],
    defaultLocale: 'ko',
  },
  ...
};

How to stop redirect with double locale?如何使用双重语言环境停止重定向?

I advise you to include more code in the question, without giving readers undefined variables or without context.我建议您在问题中包含更多代码,而不给读者未定义的变量或没有上下文。 To help us better understand the problem and help you.帮助我们更好地了解问题并帮助您。

In my opinion you are passing unnecessarily the locale variable in the template string.在我看来,您在模板字符串中传递了不必要的locale变量。

Maybe this is better like a comment but have no allow to comment yet.也许这更像是评论,但还不允许评论。

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

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