0

Im making project in next.js 13 and currently there is only 1 folder name explore that has dynamic routing.

enter image description here

in explore im mapping over a list and using as well and in link im passing index of map ( which will be id ) like .

enter image description here

in my development it works fine but when i make build and test in live / production it gives error

Cannot GET /explo

in development its http://localhost:3000/explore/0/

and then after build in live its Cannot GET /explo or http://127.0.0.1:5500/explo

why does it gets explo in live ? it should be explore/0 or explore/1 (depending on id passed)

i made a demo project there i passed a simple id of an array to my [id] page. everything worked well but after build same issue there as well. i tried using client side and server side both causing issue. i think there is something wrong when making build ?

Adnan Khan
  • 11
  • 3

1 Answers1

0

Issue fixed by using server site generation approach (SSG) in which we use generateStaticParams()

when ever we make dynamic routes ( the [id] page ) we need to use generateStaticParams() in that [id] page. this will tell next.js to render this as (SSG) not SSR Or CSR in build run time.

so by (SSG) next stores dynamic data as static and when user calls request or hits api next has already rendered and stored the dynamic data and immediatly gives user the requested data. this approach reduce latency by not hitting api for request as data is already rendered statictly and stored.

enter image description here

in my question picture i was mapping on list and sending index to explore[id] . and here you can see i used the SSG approach. the video im sharing will make it clear to you how to use (SSG) for dynamic data. https://youtu.be/UgseormfMc4

please read more about (SSG) https://nextjs.org/docs/pages/building-your-application/rendering/static-site-generation

here i used map and mentioned id's ( which in this scenario is 18 ) and i wont be changing data. if your using api or your dynamic data might change. please consider watching the video i shared or read SSG docs.

Adnan Khan
  • 11
  • 3