0

I'm creating a movie website that includes a vast amount of data. There are hundreds of thousands unique movie ids. Is there's an alternative for this case instead of listing all the ids for the routing?. Because In my case, In order to get all the ids, I have to make thousands of api calls since each api call only returns 20 movies.

Dylan Mac
  • 55
  • 7
  • No, it isn't. You can use `fallback: 'blocking'` in `getStaticPaths` to pre-generate a page when its first request comes in, rather than at build time. See [How to add new pages without rebuilding an app with +150k static pages?](https://stackoverflow.com/questions/66036558/how-to-add-new-pages-without-rebuilding-an-app-with-150k-static-pages). – juliomalves Apr 20 '22 at 21:08

1 Answers1

-1

From the documentation:

if you create a file called pages/posts/[id].js, then it will be accessible at posts/1, posts/2, etc.

So for your case, the file could be called pages/movies/[id].js, and based on the ID passed you can figure out which data you want to fetch and display on the page.

Shay Nehmad
  • 1,103
  • 1
  • 12
  • 25
  • However, In order to do that, you have to set all the routes inside the getStaticPath to make it accessible. – Dylan Mac Apr 20 '22 at 08:18
  • In my case, I have possibly millions of unique id which can be derived by making api calls. – Dylan Mac Apr 20 '22 at 08:19
  • 1
    [Relevant documentation](https://nextjs.org/docs/basic-features/data-fetching/get-static-paths). Seems like you can use the "params" to list all your IDs. If you want to statically generate the site, you need to statically list all the pages SOMEWHERE - how can `next.js` know which pages to generate? However, you can COMPUTE that list inside the `getStaticPaths` implementaiton. – Shay Nehmad Apr 20 '22 at 12:28
  • 1
    In any case, please edit your question to clarify that you want to STATICALLY RENDER the site. It's a totally different question :) – Shay Nehmad Apr 20 '22 at 12:30