not-found.js— rendered whennotFound()is called within a route segmentglobal-not-found.js— a global 404 page for unmatched URLs across the entire app (experimental)
not-found.js
When notFound() is called inside a route segment, Next.js renders the nearest not-found.js file as the response UI.
app/not-found.js
The root
app/not-found.js also handles any unmatched URL for the entire application. Users visiting a URL not handled by your app see this component.Props
not-found.js components do not accept any props.
Triggering not-found
CallnotFound() from next/navigation to trigger the not-found UI:
app/blog/[slug]/page.js
global-not-found.js (experimental)
The global-not-found.js file handles 404s at the routing level, before any layout or page is rendered. Next.js skips normal rendering and returns this global page directly.
Useful when:
- Your app has multiple root layouts (e.g.,
app/(admin)/layout.tsxandapp/(shop)/layout.tsx) with no single layout to compose a global 404 from - Your root layout uses top-level dynamic segments (e.g.,
app/[country]/layout.tsx)
next.config.ts:
next.config.ts
app/global-not-found.js. Unlike not-found.js, this file must return a full HTML document:
app/global-not-found.js
Examples
Fetching data in not-found
not-found.js is a Server Component by default. Mark it async to fetch data:
app/not-found.js
Custom metadata for not-found pages
Forglobal-not-found.js, export a metadata object or generateMetadata function:
app/global-not-found.tsx
Next.js automatically injects
<meta name="robots" content="noindex" /> for 404 pages.Version history
| Version | Changes |
|---|---|
v15.4.0 | global-not-found.js introduced (experimental) |
v13.3.0 | Root app/not-found handles global unmatched URLs |
v13.0.0 | not-found introduced |
