Complete the code to define a parallel route segment in Next.js.
export const metadata = { title: 'Dashboard' };
export default function DashboardLayout({ children }) {
return <section>[1]{children}</section>;
}The <main> tag is used to wrap the main content in a layout, which is common in Next.js layouts including parallel routes.
Complete the code to import a parallel route segment in Next.js App Router.
import [1] from './(admin)/settings/page';
When importing a parallel route segment, the folder name is used as the import name, here 'Settings' matches the folder '(admin)/settings'.
Fix the error in the parallel route segment definition by completing the blank.
export default function [1]() { return <div>Admin Settings</div>; }
The function name should match the segment name for clarity and convention, here 'Settings' matches the route segment folder.
Fill both blanks to correctly define parallel routes in Next.js App Router.
export const parallelRoutes = {
[1]: () => import('./(marketing)/home/page'),
[2]: () => import('./(admin)/dashboard/page')
};The keys in the parallelRoutes object represent the route names, matching the folder names 'marketing' and 'admin'.
Fill all three blanks to create a parallel route layout with metadata and children rendering.
export const metadata = { title: '[1]' };
export default function [2]Layout({ children }) {
return <[3]>{children}</[3]>;
}The metadata title is 'Admin Panel', the function name matches the segment 'Admin', and the children are wrapped in a semantic <section> tag.
Practice
Solution
Step 1: Understand what parallel routes do
Parallel routes allow showing multiple UI sections at the same time on a page.Step 2: Compare options with this understanding
Only To display multiple parts of a page simultaneously correctly describes this purpose; others describe unrelated behaviors.Final Answer:
To display multiple parts of a page simultaneously -> Option DQuick Check:
Parallel routes = show multiple parts [OK]
- Thinking parallel routes load pages one after another
- Confusing parallel routes with disabling navigation
- Assuming parallel routes replace client-side routing
Solution
Step 1: Recall folder naming for parallel routes
Next.js uses parentheses around folder names to mark parallel routes.Step 2: Match options to this rule
Only Using parentheses like(route)uses parentheses, which is correct for parallel routes.Final Answer:
Using parentheses like (route) -> Option AQuick Check:
Parallel routes folder = parentheses [OK]
- Using square brackets which are for dynamic routes
- Confusing with curly braces or angle brackets
- Not using any special characters for parallel routes
app/
(sidebar)/
page.jsx
(content)/
page.jsx
layout.jsxWhat will happen when the app renders
layout.jsx with parallel routes?Solution
Step 1: Understand parallel routes folder names
Folders named with parentheses define parallel routes that render simultaneously.Step 2: Apply to given structure
Both (sidebar) and (content) are parallel routes, so their pages render side by side inside layout.Final Answer:
Both sidebar and content pages render side by side inside layout -> Option AQuick Check:
Parallel routes render all named folders simultaneously [OK]
- Thinking only one parallel route renders at a time
- Assuming parallel routes need manual import to render
- Confusing parallel routes with nested routes
layout.jsx to render parallel routes:import { Slot } from 'next/navigation';
export default function Layout() {
return (
<Slot name="sidebar" />
<Slot name="content" />
);
}Why does this code cause an error?
Solution
Step 1: Check JSX syntax in return statement
The code uses <Slot name="sidebar" /> as a string literal, not as JSX tags.Step 2: Correct JSX usage
It should be <Slot name="sidebar" /> without quotes, as a self-closing JSX component.Final Answer:
Because <Slot /> should be self-closing JSX tags, not string literals -> Option BQuick Check:
JSX tags must not be strings [OK]
- Writing JSX tags as strings inside return
- Importing Slot incorrectly
- Thinking Slot can't be used in parallel routes
app/
(sidebar)/
page.jsx
(main)/
page.jsx
layout.jsxAnd in
layout.jsx:export default function Layout() {
return (
{/* What goes here? */}
);
}Solution
Step 1: Match folder names to Slot names
Folders are named (sidebar) and (main), so Slots must use these exact names.Step 2: Check code snippet for correct Slot usage
<Slot name="sidebar" /> <Slot name="main" />uses <Slot name="sidebar" /> and <Slot name="main" />, matching folder names and correct JSX syntax.Final Answer:
<Slot name="sidebar" /> <Slot name="main" /> -> Option CQuick Check:
Slot names = folder names [OK]
- Using wrong Slot names that don't match folders
- Using instead of
- Using only one Slot for multiple parallel routes
Ready to prove it?
Pass the test and this pattern moves unknown
