notFound()?Consider a Next.js 14 app router page that returns notFound() from its server component. What is the user experience?
import { notFound } from 'next/navigation'; export default function Page() { const data = null; if (!data) { notFound(); } return <div>Data found</div>; }
Think about what notFound() is designed to do in Next.js routing.
Calling notFound() in a server component tells Next.js to show the built-in 404 page. It does not crash or redirect.
Choose the code snippet that correctly triggers the 404 page using notFound() in a server component.
Remember that notFound() throws internally and does not return JSX.
Option A calls notFound() conditionally and does not return it. This is the correct usage. Options A, C, and D misuse return or call order. Option A tries to return notFound() which is invalid.
Given this code, the 404 page does not appear when data is null. What is the problem?
import { notFound } from 'next/navigation'; export default function Page() { const data = null; if (!data) { return notFound(); } return <div>{data.title}</div>; }
Check how notFound() is supposed to be used in server components.
notFound() throws internally to stop rendering and show the 404 page. Returning it as JSX is incorrect and causes the 404 not to appear.
notFound() is called inside a client component?Consider this client component that calls notFound(). What happens?
"use client"; import { notFound } from 'next/navigation'; export default function ClientPage() { notFound(); return <div>Should not render</div>; }
Think about where notFound() can be used in Next.js.
notFound() is a server-only function and cannot be called inside client components. Calling it there causes a runtime error.
notFound() is called in a deeply nested page?In a Next.js app router, if a deeply nested page calls notFound(), what is the effect on the layout and UI?
Consider how Next.js treats 404 pages in the app router with nested layouts.
When notFound() is called, Next.js replaces the entire route segment including all nested layouts with the 404 page, so the user sees a full 404 page without any parent layouts.