Next.js Discord

Discord Forum

Dynamic Routing

Answered
American Crocodile posted this in #help-forum
Open in Discord
American CrocodileOP
Hey, i have a question about dynamic route

My goal with dynamic is like this

localhost:300/order/house

localhost:300/order/shoe

localhost:300/order/car

So i want make the url after order is dynamic, but someone go to

localhost:300/order/ it redirect to localhost:3000

Is it possible?
Answered by B33fb0n3
the useParams hook is only for clientside stuff. If he want to retrieve it serverside, he can do this directly through the params.
View full answer

7 Replies

yes, add your dynamic fragement to your route config by creating a folder [dynamic] and then check if the param is empty or not. When empty redirect to /
@Coffee Coke https://nextjs.org/docs/app/building-your-application/routing/dynamic-routes /order/[order] and retrieve params using `useParams` hook
the useParams hook is only for clientside stuff. If he want to retrieve it serverside, he can do this directly through the params.
Answer
American CrocodileOP
Thank u, ima try it
American CrocodileOP
happy to help