Next.js Discord

Discord Forum

Best practice to conditionally hide layout parts (e.g. Footer) per route in Next.js App Router

Unanswered
Polar bear posted this in #help-forum
Open in Discord
Polar bearOP
Hi everyone,
I'm building a production-grade Next.js 15 application using the App Router. I have a single persistent layout.tsx at the root level that renders global UI elements like <Header />, <Footer />, etc.
However, some pages (e.g. product detail) need to hide specific parts of the layout, such as the Footer or Header, depending on the route.
I want to handle this without relying on client-side code like usePathname() or useEffect(), because many of my page.tsx files are Server Components.
I'm looking for the best practice to achieve per-route layout configuration.
Thanks in advance!

0 Replies