Next.js Discord

Discord Forum

conditionally rendering layout component based on path

Unanswered
Oak Titmouse posted this in #help-forum
Open in Discord
Oak TitmouseOP
what's the best way to make a component, such as a header in the layout not render based on the path? for example, if the path is "/example" i dont want the header to render, but it should render on any other path within the layout folder?

1 Reply

@Oak Titmouse what's the best way to make a component, such as a header in the layout not render based on the path? for example, if the path is "/example" i dont want the header to render, but it should render on any other path within the layout folder?
use route groups

app/
  layout.tsx <- don't put the header here
  example/
    page.tsx <- this one doesn't have the header
  (others)/
    layout.tsx <- put the header here
    page.tsx <- this one has the header