Next.js Discord

Discord Forum

Custom not found page for a subroute

Answered
Atlantic menhaden posted this in #help-forum
Open in Discord
Atlantic menhadenOP
I'm working on a Next.js app split into two parts: a public section at / and an admin dashboard at /admin/*. The admin dashboard has its own custom navbar and layout, separate from the main site layout. I'm trying to add a custom 404 page specifically for non-existent routes under /admin/* (e.g., /admin/not-existing-route) that uses the admin layout.

I tried placing a not-found.tsx file in app/admin/not-found.tsx, but it doesn’t catch the 404s for /admin/* only the root 404 page is triggered. How can I achieve this?
Answered by Atlantic menhaden
For anyone else stuck on this, the solution was to add a catch all segment under app/admin/[...notfound]/page.tsx. The docs are available here: https://nextjs.org/docs/pages/building-your-application/routing/dynamic-routes#catch-all-segments
View full answer

1 Reply

Atlantic menhadenOP
For anyone else stuck on this, the solution was to add a catch all segment under app/admin/[...notfound]/page.tsx. The docs are available here: https://nextjs.org/docs/pages/building-your-application/routing/dynamic-routes#catch-all-segments
Answer