Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

334
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!