Replies: 2 comments 1 reply
-
We ran into the same issue and are now trying to solve this using contexts. From the Nextjs docs:
|
Beta Was this translation helpful? Give feedback.
-
Re your simpler case: i created a simple project to show you how we can leverage middleware Layout has Header component that has backgroundColor property
In page about i need to have header bg red
In page products i need to have header bg blue Middleware <----- hope this helps if this helps don't forget to upvote this post so other people going through the same issue can benefit from this as well |
Beta Was this translation helpful? Give feedback.
-
Hello.
I have app folder structure:
I need to fetch data in the page component and pass that to layout.js?
How could i do this?
My case: Posts have different slugs for different language, component LanguageSwitch is rendered in layout, i need to pass slugs object that i got from the API to LanguageSwitch from post page.
I think i can do this with contexts, but here i probably would need to "reset" context on pages that have the same slug for different languages
Or simpler case:
Layout has Header component that has backgroundColor property
In page about i need to have header bg red
In page products i need to have header bg blue
Also data is dynamic from API, so i can't do this statically
I could go with contexts here as well (or dom manipulation), but is there something i could do via Next, like pass headerBackgroundColor as prop to layout?
Beta Was this translation helpful? Give feedback.
All reactions