0
0
NextJSframework~5 mins

Not-found page handling in NextJS - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of a not-found page in Next.js?
A not-found page shows a friendly message when a user tries to visit a page that does not exist. It helps users understand they reached a wrong or missing page.
Click to reveal answer
beginner
How do you create a custom 404 page in Next.js?
Create a file named app/not-found.tsx or pages/404.tsx with a React component that returns the UI you want to show when a page is not found.
Click to reveal answer
intermediate
What React hook can you use inside app/not-found.tsx to navigate back to a valid page?
You can use the useRouter hook from next/navigation to programmatically navigate users back to a valid page, like the homepage.
Click to reveal answer
beginner
What happens if you do not create a custom 404 page in Next.js?
Next.js will show a default 404 page with a simple message. It works but is not styled or customized for your app's look and feel.
Click to reveal answer
advanced
How can you trigger the not-found page programmatically in Next.js server components?
You can call the notFound() function from next/navigation inside a server component or server action to show the not-found page when data is missing.
Click to reveal answer
Where do you place a custom 404 page in a Next.js app router project?
AIn the <code>app/not-found.tsx</code> file
BIn the <code>pages/404.tsx</code> file
CIn the <code>public/404.html</code> file
DIn the <code>components/NotFound.tsx</code> file
What function do you import to programmatically show the not-found page in Next.js server components?
A<code>notFound()</code>
B<code>useRouter()</code>
C<code>redirect()</code>
D<code>useNotFound()</code>
What is the default behavior if no custom 404 page is created in Next.js?
AThe app crashes
BA default Next.js 404 page shows
CA blank page shows
DThe homepage loads instead
Which hook helps navigate users back from a not-found page in Next.js client components?
A<code>useState()</code>
B<code>useEffect()</code>
C<code>useRouter()</code>
D<code>useNotFound()</code>
In Next.js, what file name is used for a custom 404 page in the pages directory (not app router)?
Aerror.tsx
Bnot-found.js
C404.js
D404.tsx
Explain how to create and use a custom not-found page in a Next.js app router project.
Think about file location, component, and navigation helpers.
You got /4 concepts.
    Describe what happens when a user visits a missing page in Next.js without a custom 404 page.
    Focus on default behavior and user experience.
    You got /4 concepts.