Next.js Discord

Discord Forum

Parent layout.tsx get data from child dynamic route

Answered
Spot-breasted Oriole posted this in #help-forum
Open in Discord
Spot-breasted OrioleOP
Hi,
I have the following structure (image) and would like to put a breadcrumb component inside layout.tsx that would be displayed for all children.
If possible I would like to have this component only in layout.tsx instead of having to place one in each subfolder. Is this possible?
Right now if I access any route/ sub route I cannot see the slug params.

use client can be used as long as I can do some server side pre rendering (generateStaticParams?)

Scenario:
- /shop: Shop
- /shop/juice: Shop > Juice
- /shop/juice/orange: Shop > Juice > Orange
Answered by B33fb0n3
you can archive this, by playing (another/your) layout in the next folder (or even one layer more). Like that the layout can receive the param and render this specific breadcrumb.

Of course you can also have a client component, that handles this process. Sometimes it's good to use client components
View full answer

8 Replies

Answer
@B33fb0n3 you can archive this, by playing (another/your) layout in the next folder (or even one layer more). Like that the layout can receive the param and render this specific breadcrumb. Of course you can also have a client component, that handles this process. Sometimes it's good to use client components
Spot-breasted OrioleOP
My main concern is SEO. If I make the breadcrumb as a client component and use the pathname this could work but since the pathname would be inside Breadcrumb.tsx, I am not sure how I can pre render/ cache all possible paths.

Also if let's say I manage to implement server side rendering for the client component. How can I test if the result was generated dynamically from client side, or from server cache?
Spot-breasted OrioleOP
Thanks I will look into this
@Spot-breasted Oriole Thanks I will look into this
When will you look into this?
Spot-breasted OrioleOP
Couple hours, will close the post