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

336
Visualizações
NextJs - Additional keys were returned from getStaticPaths

I'm working on a client's project with NextJs, On the blog section we have different paths, blog/[:category], blog/[:category]/[:post] and blog/author/[:author] And to get this done I'm using getStaticPaths and getStaticProps.

I first fetch all the posts and authors from ContentfulAPI and then loop into them to create a valid path to pass it into the paths array

Ps: It works when I hard code every path individually..

thats my function:


export const getStaticPaths = async () => {

  const posts = await DataController.getEntriesByContentType(
    "componentBlog",
  );

  const blogPosts = posts.items.map(item => {
    return {params: {blog_post: [item.fields.category.replace(/\s+/g, '-').replace(/'/g, '').toLowerCase(), item.fields.slug]}}
  })

  const authors = await DataController.getEntriesByContentType(
    "author",
  );

  const authorPaths = authors.items.map(item => {
    return {params: {blog_post: ['author', item.fields.slug]}}
  })

  return {
    
    paths: [
      blogPosts,
      authorPaths,
    ],
    fallback: false,
  }
}

And i get this error when I try to access a blog link :

error - Error: Additional keys were returned from `getStaticPaths` in page "/blog/[...blog_post]". URL Parameters intended for this dynamic route must be nested under the `params` key, i.e.:

        return { params: { blog_post: ... } }

Keys that need to be moved: 0, 1, 2, 3, 4, 5, 6, 7, 8.

    at C:\Workspace\phoenix-v2\next\new-phoenix\node_modules\next\dist\build\utils.js:518:23
    at Array.forEach (<anonymous>)
    at Object.buildStaticPaths (C:\Workspace\phoenix-v2\next\new-phoenix\node_modules\next\dist\build\utils.js:492:17)    at processTicksAndRejections (internal/process/task_queues.js:95:5) {
  type: 'Error',
  page: '/blog/[...blog_post]'
}

I'm not sure why I run into this error.. thank you for helping!

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

0

You're currently passing an array with the params, use the spread operator (...) to reduce it. Docs

return {
  paths: [...blogPosts, ...authorPaths],
  ...
};
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