notFound()
A function from next/navigation that stops rendering and shows the nearest not-found.tsx with a 404 status.
In more detail
Call it when a record does not exist, such as a missing product id. It throws internally, so code after it never runs. It works in Server Components, Route Handlers and Server Actions.
Example
import { notFound } from 'next/navigation';
if (!product) notFound();Related terms
- not-found.tsx — A special file that renders a custom "not found" screen when a route does not exist or notFound() is called.
- 404 Not Found — The HTTP status meaning there is no resource at the requested address.
Taught in
- Not Found Handling: not-found.tsx & Programmatic Exits — Next.js 15 & Modern App Router Architecture