How to have a dynamic component in the path while building a static site?
Unanswered
Exotic Shorthair posted this in #help-forum
Exotic ShorthairOP
Hi everyone,
I am trying to build static next.js app but have a path with dynamic route
Like
/app/[id]
This id is stored in local storage and is dynamically generated. So at the build time I can't tell what the ID will be
What can me done here to build the app with a dynamic part in path?
I am trying to build static next.js app but have a path with dynamic route
Like
/app/[id]
This id is stored in local storage and is dynamically generated. So at the build time I can't tell what the ID will be
What can me done here to build the app with a dynamic part in path?
13 Replies
@Exotic Shorthair Hi everyone,
I am trying to build static next.js app but have a path with dynamic route
Like
/app/[id]
This id is stored in local storage and is dynamically generated. So at the build time I can't tell what the ID will be
What can me done here to build the app with a dynamic part in path?
could u describe little more please your question is that you can't create dynamic route?? or u dont know??
Exotic ShorthairOP
I can't create dynamic routes
When I do
When I do
yarn build
it says to declare generateStaticParams which must return all the possible routes or IDs.@Exotic Shorthair I can't create dynamic routes
When I do `yarn build` it says to declare generateStaticParams which must return all the possible routes or IDs.
im not familiar with yarn but u just have to do simply
npm run dev
??@let headache = null() im not familiar with yarn but u just have to do simply `npm run dev` ??
Exotic ShorthairOP
Yes I can run in dev mode but I have to build a static site without next with just plain HTML, CSS, JS
Add
export const dynamicParams = true
at the top of the file in /[id]/page.tsxYou will still need next.js to generate these pages on demand tho, since they can’t be pre-rendered at build time, ahead of time
@Exotic Shorthair solved?
Exotic ShorthairOP
Hey @LuisLl , no still facing the problem
Did you try
If you want a dynamic route segment like *app/[id]
I you need to return the ids you want to generate pages for from generateStaticParams({params})
If you can’t provide the id ahead of time then it can’t be pre-render and the page will have to be dynamic and generate at request time.
generateStaticParams
?If you want a dynamic route segment like *app/[id]
I you need to return the ids you want to generate pages for from generateStaticParams({params})
If you can’t provide the id ahead of time then it can’t be pre-render and the page will have to be dynamic and generate at request time.
That’s just how it works, too can’t generate static pages for ids you don’t know ahead of time, when Next.js is building your app
@Exotic Shorthair solved?