Next.js Discord

Discord Forum

Styling component in RootLayout #Layout

Unanswered
Transvaal lion posted this in #help-forum
Open in Discord
Transvaal lionOP
Hey guys. I have an app Layout including components like:
<Header />
{children}
<Footer />
I need to style my Header background and text color depending on which page I route, is it real without using client component with useEffect?

5 Replies

not with a single layout, you need a client component so it re-renders on page changes
client components are still pre-rendered in the server so this is a perfectly fine solution
Transvaal lionOP
@Rafael Almeida
Will it be a good solution if I create a layout ( with nesessary props in Header ) in page folders where I need another styles?
app/
├── layout.tsx
├── (groupA)/
│   ├── layout.tsx
│   └── about/page.tsx
└── (groupB)/
    ├── layout.tsx
    └── foo/page.tsx

if you structure your folders like this, you can have a header in groupA with style A and a different header for the routes in groupB