The dynamic routing has me confused, chatgpt and the website conflict heavily.
Unanswered
Toyger posted this in #help-forum
ToygerOP
I have a route defined as
app/instructions/[number]/page.tsx
I want to print the url parameter or use it to render a server side component as below
https://localhost:3000/instructions/1
I want to print 1 or query the db for instruction 1
why is this not working?
I haven't found any instructions online that correctly extract and use this param.
app/instructions/[number]/page.tsx
I want to print the url parameter or use it to render a server side component as below
https://localhost:3000/instructions/1
I want to print 1 or query the db for instruction 1
why is this not working?
I haven't found any instructions online that correctly extract and use this param.
8 Replies
Common paper wasp
Common paper wasp
If you want to query the Db for something when that route is requested, you'll probably want an API route to handle fetching the data from the Db and returning it to the user
@Common paper wasp If you want to query the Db for something when that route is requested, you'll probably want an API route to handle fetching the data from the Db and returning it to the user
i dont see what api route has to do with this, but yeah dynamic route is the way to go (may need to disable caching for page to see the db req and console every request)
ToygerOP
So I figured out how to do this. I may sound super dumb y'all but it was not immediately clear that only slug and id were valid in the [tag]
I had [whatevertextIchose] and as soon as I changed it to slug it worked.
@Toyger I had [whatevertextIchose] and as soon as I changed it to slug it worked.
uh no.
whatevertextIchose should work too. as long as you access params.whatevertextIchose and not params.slug or params.idthe above code works
ToygerOP
This is why you don't stay up and code all night. 🤡
I did eventually realize this solution, but for whatever reason I must have mispelled something or something similar
I did eventually realize this solution, but for whatever reason I must have mispelled something or something similar