Complete the code to import the Next.js not-found helper.
import { [1] } from 'next/navigation';
The notFound function from next/navigation is used to trigger the 404 page in Next.js App Router.
Complete the code to call the function that shows the 404 page inside a React component.
export default function Page() {
if (!data) {
[1]();
}
return <div>Content</div>;
}Calling notFound() inside the component triggers Next.js to render the 404 page.
Fix the error in the code to correctly trigger the 404 page when no post is found.
import { notFound } from 'next/navigation'; export default async function Post({ params }) { const post = await getPost(params.id); if (post === null) { [1]; } return <article>{post.title}</article>; }
notFound() instead of calling it.You must call notFound() as a function to trigger the 404 page. Returning it as JSX or redirecting manually is incorrect.
Fill both blanks to create a server component that fetches data and shows 404 if missing.
import { [1] } from 'next/navigation'; export default async function User({ params }) { const user = await fetchUser(params.id); if (!user) { [2](); } return <div>{user.name}</div>; }
Import and call notFound() to handle missing data by showing the 404 page.
Fill all three blanks to create a dynamic route page that fetches a product, shows 404 if missing, and displays the product name.
import { [1] } from 'next/navigation'; export default async function ProductPage({ params }) { const product = await getProduct(params.[2]); if (!product) { [3](); } return <h1>{product.name}</h1>; }
Import and call notFound() to show 404. Use id from params to fetch the product.