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

268
Views
Why do we only need getStaticPaths() when we use getStaticProps?

If we have a dynamic route

[id].js

function id() {
  return <h1>Hello World</h1>
}
export default id

and we build the static pages with npm run build, the result is the [id].html page. Any route with /something will work and displays Hello World.

But if we generate the content of the page dynamically by using the return value of getStaticProps() in the component:

function id(props) {
  const { test } = props
  return <h1>{test.foo}</h1>
}
export default id

Then we need getStaticPaths() again to specify the possible routes.

Why do we only need getStaticPaths() when we use getStaticProps?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The nextjs docs put it simply:

If a page has Dynamic Routes and uses getStaticProps, it needs to define a list of paths to be statically generated.

getStaticPaths is required for dynamic SSG pages because that how Vercel decided to make it.


If you want to use getStaticProps while maintaining the behavior of not requiring predefined routes from getStaticPaths, you can use fallback: true to tell nextjs to render routes even if they are not predefined by getStaticPaths.

You can send an empty array of paths and set fallback: true:

export async function getStaticPaths() {
  const paths = [];
  return { paths, fallback: true };
}

This will result in all routes still being accessible, like the behavior from the first part of your question. Here's a full example on codesandbox. In the example, try going to /test/any-route-you-want and note that the route will still be rendered: Edit blissful-dan-40qkvq

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!