Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

211
Visualizações
Next.js getStaticPaths and locales

I'm working on a Next.js project where I want to implement locales for dynamic pages using i18n.

The following is defined in my next.config.js file:

module.exports = {
  i18n: {
    locales: ["en-US", "da-DK", "se-SE", "no-NO", "nl-NL"],

    defaultLocale: "en-US",
  },

  reactStrictMode: true,

  images: {
    domains: ["images.ctfassets.net"],
  },
};

I have a getStaticPaths function I'm using to get data from our CMS (Contentful) which is working fine when I specify a single locale:

export async function getStaticPaths() {
  const categories = await ContentfulCategories.getAll();

  const paths = categories.map((category) => {
    return {
      params: { category: category.slug },
      locale: "en-US",
    };
  });

  return {
    paths,
    fallback: false,
  };
}

And here is where I'm getting stuck. I've tried inserting an array of the locales from the next config file, but that doesn't work and gives me the following message even though it is defined in the config file:

Error: Invalid locale returned from getStaticPaths for /integration/category/[category], the locale en-US,da-DK,se-SE,no-NO,nl-NL is not specified in next.config.js

How can I specify multiple locales so for instance when I've set the site to example.com/en-US/ it will generate my dynamic page for that locale or one of the others from the config file?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You are using Sub-path Routing strategy. You need to loop available locales from context in getStaticPaths.

From the docs:

When leveraging getStaticPaths, the configured locales are provided in the context parameter of the function under locales and the configured defaultLocale under defaultLocale.

Basically two loops, first categories & then locales. You can use a flatmap to solve this, pseudocode -

export async function getStaticPaths({ locales }) {
 const paths = categories.flatMap(category => {
    return locales.map(locale => {
      return {
       params: { category: category.slug },
       locale: locale,
      };
    });
 });
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda