Bird
Raised Fist0
NextJSframework~20 mins

Parallel routes (@slot) in NextJS - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Parallel Routes Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate
2:00remaining
What will be rendered by this Next.js parallel route setup?

Given the following folder structure and code snippets, what will the rendered output be?

Folder structure:

app/
  layout.js
  page.js
  (sidebar)/
    layout.js
    page.js

app/layout.js:

export default function RootLayout({ children }) {
  return (
    <html>
      <body>
        <div>Root Layout</div>
        {children}
      </body>
    </html>
  )
}

app/page.js:

export default function HomePage() {
  return <div>Home Page</div>
}

app/(sidebar)/layout.js:

export default function SidebarLayout({ children }) {
  return <aside>Sidebar Layout {children}</aside>
}

app/(sidebar)/page.js:

export default function SidebarPage() {
  return <div>Sidebar Page</div>
}

And the route is accessed as: / with parallel route sidebar rendered in a slot.

A&lt;html&gt;&lt;body&gt;&lt;div&gt;Root Layout&lt;/div&gt;&lt;aside&gt;Sidebar Layout &lt;div&gt;Sidebar Page&lt;/div&gt;&lt;/aside&gt;&lt;div&gt;Home Page&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;
B&lt;html&gt;&lt;body&gt;&lt;div&gt;Root Layout&lt;/div&gt;&lt;div&gt;Sidebar Page&lt;/div&gt;&lt;div&gt;Home Page&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;
C&lt;html&gt;&lt;body&gt;&lt;div&gt;Root Layout&lt;/div&gt;&lt;aside&gt;Sidebar Layout &lt;div&gt;Home Page&lt;/div&gt;&lt;/aside&gt;&lt;/body&gt;&lt;/html&gt;
D&lt;html&gt;&lt;body&gt;&lt;div&gt;Root Layout&lt;/div&gt;&lt;div&gt;Home Page&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;
Attempts:
2 left
💡 Hint

Remember that parallel routes require the parent layout to destructure and render the slot prop named after the route group (e.g., {sidebar}).

📝 Syntax
intermediate
2:00remaining
Which code correctly defines a parallel route slot in Next.js layout?

In Next.js App Router, how do you correctly define a slot for a parallel route named sidebar inside a layout component?

A
export default function Layout({ children, sidebar }) {
  return &amp;lt;div&amp;gt;{children}&amp;lt;div&amp;gt;{sidebar}&amp;lt;/div&amp;gt;&amp;lt;/div&amp;gt;
}
B
export default function Layout({ children, slots }) {
  return &amp;lt;div&amp;gt;{children}{slots.sidebar}&amp;lt;/div&amp;gt;
}
C
export default function Layout({ children }) {
  return &amp;lt;div&amp;gt;{children}&amp;lt;slot name="sidebar" /&amp;gt;&amp;lt;/div&amp;gt;
}
D
export default function Layout({ children, sidebar }) {
  return &amp;lt;div&amp;gt;{children}{sidebar}&amp;lt;/div&amp;gt;
}
Attempts:
2 left
💡 Hint

Parallel route slots are passed as props named after the route.

🔧 Debug
advanced
2:00remaining
Why does this parallel route slot not render content?

Given this layout code in Next.js App Router:

export default function RootLayout({ children }) {
  return (
    <html>
      <body>
        <div>Root</div>
        {children}
        {sidebar}
      </body>
    </html>
  )
}

And the parallel route is named sidebar. The sidebar content does not appear on the page. What is the cause?

AThe 'sidebar' prop must be destructured from the function parameters to be used.
BThe children prop overwrites the sidebar prop, so sidebar is ignored.
CParallel routes require a special hook to access their content, not props.
DThe layout does not receive a prop named 'sidebar', so {sidebar} is undefined causing no render.
Attempts:
2 left
💡 Hint

Check how the function parameters receive props.

❓ state_output
advanced
2:00remaining
What is the output when parallel routes update state independently?

Consider a Next.js app with two parallel routes: main and sidebar. Each route has a button that increments its own counter state.

If you click the button in the sidebar route, what happens to the main route's counter display?

NextJS
<!-- main/page.js -->
import { useState } from 'react';
export default function MainPage() {
  const [count, setCount] = useState(0);
  return (
    <div>
      <p>Main count: {count}</p>
      <button onClick={() => setCount(count + 1)}>Increment Main</button>
    </div>
  );
}

<!-- sidebar/page.js -->
import { useState } from 'react';
export default function SidebarPage() {
  const [count, setCount] = useState(0);
  return (
    <div>
      <p>Sidebar count: {count}</p>
      <button onClick={() => setCount(count + 1)}>Increment Sidebar</button>
    </div>
  );
}
AClicking sidebar button increments both sidebar and main counts.
BClicking sidebar button increments sidebar count only; main count stays the same.
CClicking sidebar button resets main count to zero.
DClicking sidebar button causes an error because state is shared incorrectly.
Attempts:
2 left
💡 Hint

Each parallel route has its own component and state.

🧠 Conceptual
expert
2:00remaining
Why use parallel routes with @slot in Next.js App Router?

What is the main advantage of using parallel routes with the @slot feature in Next.js App Router?

AThey replace the need for client-side routing by preloading all pages at build time.
BThey automatically optimize server-side rendering by batching all routes into a single request.
CThey allow rendering multiple UI sections independently with their own layouts and state, improving modularity and user experience.
DThey enforce a strict single layout for the entire app, simplifying CSS styling.
Attempts:
2 left
💡 Hint

Think about how parallel routes help organize UI parts.

Practice

(1/5)
1. What is the main purpose of using @slot in Next.js parallel routes?
easy
A. To display multiple UI parts simultaneously in different route segments
B. To fetch data from an API endpoint
C. To define server-side rendering behavior
D. To create dynamic API routes

Solution

  1. Step 1: Understand the role of @slot

    @slot is used to show multiple UI parts at once by matching route segments.
  2. Step 2: Identify the purpose in parallel routes

    It allows different UI sections to render in parallel, improving layout flexibility.
  3. Final Answer:

    To display multiple UI parts simultaneously in different route segments -> Option A
  4. Quick Check:

    Parallel routes use @slot to show multiple UI parts [OK]
Hint: Remember: @slot shows multiple UI parts at once [OK]
Common Mistakes:
  • Confusing @slot with data fetching
  • Thinking @slot controls API routes
  • Assuming @slot is for server rendering only
2. Which of the following is the correct syntax to define a parallel route slot named sidebar in Next.js?
easy
A. export const @slot sidebar = () => <div>Sidebar</div>;
B. export const slot_sidebar = () => <div>Sidebar</div>;
C. export const sidebar = () => <div>Sidebar</div>;
D. export const SidebarSlot = () => <div>Sidebar</div>;

Solution

  1. Step 1: Recall parallel route slot syntax

    Slots are exported as named exports matching the slot name, e.g., export const sidebar.
  2. Step 2: Check each option

    export const sidebar = () => <div>Sidebar</div>; correctly exports a constant named sidebar as a React component.
  3. Final Answer:

    export const sidebar = () => <div>Sidebar</div>; -> Option C
  4. Quick Check:

    Slot name matches export const name [OK]
Hint: Export slot as named const matching slot name [OK]
Common Mistakes:
  • Using @slot keyword in export
  • Prefixing slot name incorrectly
  • Using PascalCase instead of slot name
3. Given this Next.js parallel route layout code:
export const header = () => <header>Header</header>;
export const footer = () => <footer>Footer</footer>;

export default function Page() {
  return <main>Main Content</main>;
}

What will be rendered on the page?
medium
A. Only <main>Main Content</main> is rendered
B. <header>Header</header>, <main>Main Content</main>, and <footer>Footer</footer> are all rendered
C. Only <header>Header</header> and <footer>Footer</footer> are rendered
D. Syntax error due to missing @slot usage

Solution

  1. Step 1: Understand parallel route slots rendering

    Slots like header and footer render alongside the default export component.
  2. Step 2: Combine all parts

    The page renders header, main content, and footer together as parallel UI parts.
  3. Final Answer:

    <header>Header</header>, <main>Main Content</main>, and <footer>Footer</footer> are all rendered -> Option B
  4. Quick Check:

    Parallel routes render all slots plus default [OK]
Hint: Slots and default export render together [OK]
Common Mistakes:
  • Thinking only default export renders
  • Assuming slots need explicit @slot tags in JSX
  • Confusing syntax error with missing @slot
4. You wrote this code for a parallel route slot:
export const sidebar = () => <div>Sidebar</div>;

export default function Page() {
  return <main>Main</main>;
}

But the sidebar does not appear on the page. What is the likely cause?
medium
A. The slot name sidebar does not match any route segment
B. You forgot to import React
C. The default export must be named sidebar
D. Parallel routes require class components, not functions

Solution

  1. Step 1: Check slot name and route segment matching

    Slots render only if their name matches a parallel route segment in the folder structure.
  2. Step 2: Identify mismatch issue

    If no route segment named sidebar exists, the slot won't render.
  3. Final Answer:

    The slot name sidebar does not match any route segment -> Option A
  4. Quick Check:

    Slot name must match route segment [OK]
Hint: Match slot name exactly to route segment folder [OK]
Common Mistakes:
  • Assuming React import is required in Next.js 13+
  • Thinking default export must be slot named
  • Believing only class components work for slots
5. You want to create a layout with parallel routes showing a nav bar and a content area side by side. Which folder structure and code setup correctly implements this using @slot?
hard
A. Folders: app/(nav)/page.tsx and app/(content)/page.tsx with export const nav = () => <nav>Nav</nav>; in nav folder and export default function Page() { return <main>Content</main>; } in content folder
B. Folders: app/(nav)/page.tsx and app/(content)/page.tsx with export default function Nav() { return <nav>Nav</nav>; } and export default function Content() { return <main>Content</main>; }
C. Folders: app/nav/page.tsx and app/content/page.tsx with export default function Nav() { return <nav>Nav</nav>; } and export default function Content() { return <main>Content</main>; }
D. Folders: app/nav/page.tsx and app/content/page.tsx with export const nav = () => <nav>Nav</nav>; in nav folder and export default function Page() { return <main>Content</main>; } in content folder

Solution

  1. Step 1: Understand parallel route folder naming

    Parallel routes use folder names without parentheses to define slots, e.g., nav and content.
  2. Step 2: Match slot export and default export

    In nav folder, export export const nav for the slot; in content folder, export default the main content.
  3. Step 3: Verify options

    Folders: app/nav/page.tsx and app/content/page.tsx with export const nav = () => <nav>Nav</nav>; in nav folder and export default function Page() { return <main>Content</main>; } in content folder correctly uses folders app/nav and app/content with proper exports.
  4. Final Answer:

    Folders: app/nav/page.tsx and app/content/page.tsx with export const nav and default export in content -> Option D
  5. Quick Check:

    Folder names match slot names without parentheses [OK]
Hint: Use folder names matching slot names without parentheses [OK]
Common Mistakes:
  • Using parentheses in folder names for slots
  • Exporting slots as default exports
  • Mixing slot export and default export roles
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard