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

Taught in

References