How to define props for layouts based on route #71112
Replies: 1 comment 1 reply
-
I think you are in the right path with idea 1.
Client components are still SSR'd, though, but yeah, you cannot access context, nor props from a client component, into a server component. Though you can probably use composition, within these client components, to determine which server components to render. https://nextjs.org/docs/app/building-your-application/rendering/composition-patterns#interleaving-server-and-client-components |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have been looking through the docs and other resources about the app router, but it's still not clear to me what the best pattern for this is:
I have a Layout file which wraps around many pages. Depending on what route is user is viewing, I need things in that parent layout to update. Examples:
i18ntranslations as well as text that needs to be translated. Based on the page route, this provider should be able know whichnamespacesto load/initialize to properly translate all the text in the layout and its children. If I move that provider to the page file, its parent layout wont translate. If I use it in both places, it gets initialized twice, which causes bugs.I've been scratching my head thinking about how to set that up. Ideas I've had are:
useSelectedLayoutSegmentsin the parent layout, and then roll my own route-matching decision tree in a util to get the needed props. This requires client components, however, and I'm not sure if that will mess up server-side rendering the translations, etc..What's the best way?
Beta Was this translation helpful? Give feedback.
All reactions