I'm using NextJS to build a frontend for a database which currently has few thousand products and this number is expected to grow by a lot. So, my site/products/
route works fine. I want to add a route to view individual products like site/products/{sku}
. I created a dynamic route with a dummy component and expected it to work but it I was constantly getting 404 error.
On some research I found that to facilitate dynamic routing, the page component should make use of the getStatiPaths
and getStaticProps
to pre-render all the pages so that they can be served.
This behavior would've been useful for a blog, but in my case I don't want to generate few thousand pages everytime I do a npm run build
. I want to be able to make an API call with the sku
value I get from the url and generate the page dynamically on the client or better yet do this on the server and send the rendered html to the client.
How do I achieve this, is my thinking wrong in this?