importing data into [slug]
i have a '/craft' page where i display all the craft titles. at '/craft/{id}' i have to display a specific craft.
how do people usually import the data for slug pages depending upon the id? also how do you import custom components for specific pages?
11 Replies
Routing: Dynamic Routes
Dynamic Routes are pages that allow you to add custom params to your URLs. Start creating Dynamic Routes and learn more here.
i know how to get the id.
currently this is my file structure
/craft/page.tsx
/craft/craft-1/page.tsx
/craft/craft-2/page.tsx
each craft-n/page has different client react components. how do i store these pages and import them depending upon the id
is there an example repo?
you can render a different components based on the slug
idk how app dir would cache that
surely you can just hardcode
/craft/craft-n/page.tsx
for each thing you need a specific component for, and then use /craft/[id]/page.tsx
as a fallback?i was thinking the same thing, but i dont think this the right way
currently am i hardcoding the pages. i thought there might an easy way with slugs, as i could just plug the components and write the reusable functions directly into [slug]/page.tsx
Could you put the shared stuff into a separate component and add the specific stuff as props in each page?
the shared stuff will all go into layout.tsx
and yes, the specific stuff could be added from props
If you really want to try
You can use dynamic imports and props
what u could do is use it like this: files=/craft/[slug]/page.tsx
hope this is helpfull and if i am wrong please correct me
wont be server rendered 😦
what I just send should be server rendered
have u already found a solution?