Skip to main content
Next.js provides two conventions for 404 pages:
  • not-found.js — rendered when notFound() is called within a route segment
  • global-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

Call notFound() 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.tsx and app/(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)
Enable in next.config.ts:
next.config.ts
Create 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

For global-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