0
0
NextJSframework~20 mins

Nested routes with folders in NextJS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Nested Routes Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is rendered by this nested route component?
Consider a Next.js app using the App Router. The folder structure is:

app/dashboard/page.tsx
app/dashboard/settings/page.tsx

If the user visits /dashboard/settings, what will be rendered?
NextJS
app/dashboard/page.tsx
export default function Dashboard() {
  return <h1>Dashboard Home</h1>
}

app/dashboard/settings/page.tsx
export default function Settings() {
  return <h2>Settings Page</h2>
}
ANothing is rendered because nested routes require layout files.
BBoth <h1>Dashboard Home</h1> and <h2>Settings Page</h2> are rendered.
COnly <h1>Dashboard Home</h1> is rendered.
DOnly <h2>Settings Page</h2> is rendered.
Attempts:
2 left
💡 Hint
Think about how Next.js renders page components in nested folders without layouts.
📝 Syntax
intermediate
1:30remaining
Which file name correctly defines a nested route in Next.js App Router?
You want to create a nested route at /blog/post. Which file path and name is correct?
Aapp/blog/post/page.tsx
Bapp/blog-post/page.tsx
Capp/blog/post.tsx
Dapp/blog/post/index.tsx
Attempts:
2 left
💡 Hint
Next.js App Router uses folders for routes, not file names with dots.
🔧 Debug
advanced
2:00remaining
Why does visiting /profile/settings show a 404 error?
Given this folder structure:

app/profile/page.tsx
app/profile/settings.tsx

Visiting /profile/settings returns 404. Why?
ABecause nested routes require a folder named settings with a page.tsx inside, not a file named settings.tsx.
BBecause the file settings.tsx must be named settings/page.tsx to work.
CBecause the profile folder is missing a layout.tsx file.
DBecause Next.js does not support nested routes under profile.
Attempts:
2 left
💡 Hint
Check how nested routes are defined in the App Router.
state_output
advanced
2:30remaining
What is the output when navigating between nested routes with shared layout?
Given this folder structure:

app/dashboard/layout.tsx
app/dashboard/page.tsx
app/dashboard/reports/page.tsx

The layout.tsx contains a state hook that increments a counter on button click.

What happens to the counter state when navigating from /dashboard to /dashboard/reports?
NextJS
app/dashboard/layout.tsx
'use client'
import { useState } from 'react'
export default function DashboardLayout({ children }) {
  const [count, setCount] = useState(0)
  return (
    <>
      <button onClick={() => setCount(count + 1)}>Increment {count}</button>
      <main>{children}</main>
    </>
  )
}

app/dashboard/page.tsx
export default function Dashboard() {
  return <h1>Dashboard Home</h1>
}

app/dashboard/reports/page.tsx
export default function Reports() {
  return <h2>Reports Page</h2>
}
AThe counter increments twice automatically on navigation.
BThe counter resets to 0 when navigating to /dashboard/reports.
CThe counter state is preserved and increments continue from previous value.
DThe counter state is lost and causes an error.
Attempts:
2 left
💡 Hint
Layouts in Next.js persist state across nested routes.
🧠 Conceptual
expert
3:00remaining
How does Next.js App Router handle parallel nested routes with folders?
You want to render two different nested routes side-by-side under /dashboard:

- /dashboard/analytics
- /dashboard/notifications

You create folders app/dashboard/analytics and app/dashboard/notifications each with page.tsx.

How do you configure the layout to render both routes simultaneously?
APlace both page.tsx files inside the same folder and import them in layout.tsx to render side-by-side.
BUse named slots in layout.tsx with <Slot name="analytics" /> and <Slot name="notifications" /> and create parallel routes folders with @analytics and @notifications.
CUse nested layouts inside each folder and rely on default rendering order to show both routes.
DCreate a single page.tsx that conditionally renders analytics or notifications based on URL.
Attempts:
2 left
💡 Hint
Parallel routes use special folder names with @ and named slots in layouts.