Displaying unique content in when using dynamic route.
Answered
codewithmide posted this in #help-forum
Hi guys, is it possible to display unique contents on the UI when using dynamic route.
Answered by Asian black bear
Yes, of course. You can use the path params to guide rendering however you like.
32 Replies
Asian black bear
Yes, of course. You can use the path params to guide rendering however you like.
Answer
@Asian black bear Yes, of course. You can use the path params to guide rendering however you like.
Thank you for the response. Is there an article/video that talks about how to fully utilize the ‘params’ keyword.
Asian black bear
It might help if you described what you are trying to accomplish or some insight about what part of the concept is confusing.
They are a lot like queryString values, except they are mandatory.
Ok here it is.
I’m building an app where users can find vendors easily… Now I have a long list of vendors that I want to generate a profile for, instead of having to create a component for each of these vendors, I think using dynamic route could help solve that problem by making use of the template in my ‘page.tsx’ file.
I’m building an app where users can find vendors easily… Now I have a long list of vendors that I want to generate a profile for, instead of having to create a component for each of these vendors, I think using dynamic route could help solve that problem by making use of the template in my ‘page.tsx’ file.
Use the path parameter to lookup data about the specific vendor in that fetching function, then it will be a page prop that you can template in
Thanks for sharing, I've read through the docs. I noticed that i need to pull these data from an API. Is it possible to use a json for this? The information i wish to display are available locally
Asian black bear
You could load a json from the bundle and chop it up in usestaticprops
If you read it directly from the react component it will send the entire json file to the client!
Thank you. Still not getting it though.
@Asian black bear do you mind me sharing the GitHub repo link with you?
Asian black bear
@codewithmide go for it
Asian black bear
This looks right, next shouldn't send the entire JSON file
you can check by doing 'view source' on a page loaded from a production build, and ensuring that no vendor info is inside besides the one for that page
I thought you were using the pages directory
Asian black bear
@codewithmide Sorry, I always forget this doesn't ping people that started threads
This is the correct documentation for app dir
@alfon This is the correct documentation for app dir
Asian black bear
Pretty sure they are more curious how ssr/isr works with data fetching, and path params are just a segway to it
icic
@alfon https://nextjs.org/docs/app/building-your-application/routing/dynamic-routes
Yh. I’ve gone through it but I couldn’t find a way to pass a json. Most of the examples there are using API
@codewithmide Yh. I’ve gone through it but I couldn’t find a way to pass a json. Most of the examples there are using API
Asian black bear
You can just import it in a server component, and it will load the whole file server side, but you can trim it down for the client
import vendors from "./vendors.json"When you get a lot it might be impractical, but for a few hundred (or even thousand) lines, just fine
Oh that should work
Thank you, I’ll try that out and give you a feedback
Asian black bear
@codewithmide glad you got it!