Next.js Discord

Discord Forum

How to pass props to a dynamic route?

Answered
Schweizer Laufhund posted this in #help-forum
Open in Discord
Schweizer LaufhundOP
So in my app I'm redirecting my user to a dynamically generated route but I want to give the route some props in order to display what I need on the dynamic page
Answered by B33fb0n3
via a link you can only access the stuff inside the string (so parts of the url and searchparams). So currently I don't see any other way.

Imagine a user gets the link and wasn't on your page ever. What does your page know? Only the url stuff
View full answer

16 Replies

if your "props" are static, you can define them in your dynamic component. Else: where does the "dynamic" data that you want to share as props comes from? From a database/cms/... then fetch it @Schweizer Laufhund
@B33fb0n3 if your "props" are static, you can define them in your dynamic component. Else: where does the "dynamic" data that you want to share as props comes from? From a database/cms/... then fetch it <@671454109819207711>
Schweizer LaufhundOP
i dont have any identifiers in the dynamic route aside from the name of the route that would allow me to fetch the data though.
so your data is dynamic and you don't have any connection to get the data, that you want to get. Have I understood that right?
@B33fb0n3 so your data is dynamic and you don't have any connection to get the data, that you want to get. Have I understood that right?
Schweizer LaufhundOP
yeah so my data is in a database but i have no way of querying the database since i dont have any props like an id or something
all i have is the dynamic segment
@Schweizer Laufhund all i have is the dynamic segment
ok and you can't get the "prop-data" with your id of your dynamic fragment?
@B33fb0n3 ok and you can't get the "prop-data" with your id of your dynamic fragment?
Schweizer LaufhundOP
the way that its set up now, no the id is just a string that i cant use to query my db
i could probably change the name of the dynamic segment but i wanted to see if there was a way for me to pass props down
@Schweizer Laufhund i could probably change the name of the dynamic segment but i wanted to see if there was a way for me to pass props down
via a link you can only access the stuff inside the string (so parts of the url and searchparams). So currently I don't see any other way.

Imagine a user gets the link and wasn't on your page ever. What does your page know? Only the url stuff
Answer
@Schweizer Laufhund solved?
if (solved) {
   await markAsSolution();
} else {
   throw new Error("What's missing to solve your question?")?
}
@Schweizer Laufhund Error while closing thread: What's missing to solve your question?
@Schweizer Laufhund ?
@B33fb0n3 <@671454109819207711> ?
Schweizer LaufhundOP
Solved
@Schweizer Laufhund Solved
great to hear. Please mark a message as solution