Next.js Discord

Discord Forum

Remove layout.tsx components in notFound() page

Answered
Afghan Hound posted this in #help-forum
Open in Discord
Afghan HoundOP
Hello, i have a dynamic route which calls notFound() if something fails. But how do i remove for example the <Header/> an <Footer/> i have in the layout.tsx for the successful routes.
Answered by joulev
app/
  layout.tsx <- root layout but not with <Header> and <Footer>
  (all)/
    layout.tsx <- <Header> and <Footer> here
    something/
      page.tsx <- throw notFound()
View full answer

5 Replies

@Afghan Hound Hello, i have a dynamic route which calls `notFound()` if something fails. But how do i remove for example the `<Header/>` an `<Footer/>` i have in the `layout.tsx` for the successful routes.
app/.../
  not-found.tsx
  (is-found)/
    layout.tsx <- <Header> and <Footer> here
    something/
      page.tsx <- throw notFound()

try this
Afghan HoundOP
but i dont want a custom 404. i want the default next.js one
@Afghan Hound but i dont want a custom 404. i want the default next.js one
in that case remove the Header and Footer from the root layout
app/
  layout.tsx <- root layout but not with <Header> and <Footer>
  (all)/
    layout.tsx <- <Header> and <Footer> here
    something/
      page.tsx <- throw notFound()
Answer
Afghan HoundOP
alright thanks!