0
0
NextJSframework~20 mins

Not-found page handling in NextJS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Next.js NotFound Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What happens when a Next.js page returns notFound()?

Consider a Next.js 14 app router page that returns notFound() from its server component. What is the user experience?

NextJS
import { notFound } from 'next/navigation';

export default function Page() {
  const data = null;
  if (!data) {
    notFound();
  }
  return <div>Data found</div>;
}
AThe page redirects to the home page automatically.
BThe page renders an empty div with no content.
CThe user sees the default 404 page provided by Next.js.
DThe app crashes with a runtime error.
Attempts:
2 left
💡 Hint

Think about what notFound() is designed to do in Next.js routing.

📝 Syntax
intermediate
2:00remaining
Which code correctly triggers a 404 page in Next.js app router?

Choose the code snippet that correctly triggers the 404 page using notFound() in a server component.

A
import { notFound } from 'next/navigation';

export default function Page() {
  if (true) {
    notFound();
  }
  return &lt;div&gt;Content&lt;/div&gt;;
}
B
import { notFound } from 'next/navigation';

export default function Page() {
  notFound();
  return &lt;div&gt;Will not render&lt;/div&gt;;
}
C
import { notFound } from 'next/navigation';

export default function Page() {
  if (true) {
    return notFound();
  }
  return &lt;div&gt;Content&lt;/div&gt;;
}
D
import { notFound } from 'next/navigation';

export default function Page() {
  return notFound();
}
Attempts:
2 left
💡 Hint

Remember that notFound() throws internally and does not return JSX.

🔧 Debug
advanced
2:00remaining
Why does this Next.js page not show the 404 page as expected?

Given this code, the 404 page does not appear when data is null. What is the problem?

NextJS
import { notFound } from 'next/navigation';

export default function Page() {
  const data = null;
  if (!data) {
    return notFound();
  }
  return <div>{data.title}</div>;
}
AThe component must be a client component to use <code>notFound()</code>.
BReturning <code>notFound()</code> is incorrect; it should be called without return.
CThe import statement for <code>notFound</code> is missing curly braces.
DThe <code>data</code> variable should be fetched asynchronously.
Attempts:
2 left
💡 Hint

Check how notFound() is supposed to be used in server components.

state_output
advanced
2:00remaining
What is the rendered output when notFound() is called inside a client component?

Consider this client component that calls notFound(). What happens?

NextJS
"use client";
import { notFound } from 'next/navigation';

export default function ClientPage() {
  notFound();
  return <div>Should not render</div>;
}
AThe component renders the div content normally.
BThe 404 page is shown as expected.
CThe page redirects to the home page.
DThe app crashes with a runtime error because <code>notFound()</code> is server-only.
Attempts:
2 left
💡 Hint

Think about where notFound() can be used in Next.js.

🧠 Conceptual
expert
3:00remaining
How does Next.js handle nested layouts when 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?

ANext.js replaces the entire page including all layouts with the 404 page.
BOnly the nested page content is replaced by the 404 page; layouts remain visible.
CNext.js throws an error and does not render anything.
DThe 404 page is shown inside the deepest layout only, leaving outer layouts intact.
Attempts:
2 left
💡 Hint

Consider how Next.js treats 404 pages in the app router with nested layouts.