Parallel routes let you show different parts of a page at the same time without waiting for one to finish loading. This helps make your app faster and smoother.
Parallel routes concept in NextJS
app/layout.js app/(group1)/page.js app/(group2)/page.js // In your layout.js export default function RootLayout({ children, group1, group2 }) { return ( <html> <body> <div> <div>{group1}</div> <div>{group2}</div> {children} </div> </body> </html> ) } // Use parallel routes by defining folders with parentheses // and destructuring matching props in the parent layout
Parallel routes use folder names with parentheses to separate routes.
In the parent layout, destructure props matching the folder names and render them like {group1}.
// Folder structure example: // app/layout.js // app/(sidebar)/page.js // app/(content)/page.js // app/layout.js export default function RootLayout({ sidebar, content }) { return ( <html> <body> <div style={{ display: 'flex' }}> <aside style={{ width: '200px' }}> {sidebar} </aside> <main style={{ flex: 1 }}> {content} </main> </div> </body> </html> ) }
// app/(sidebar)/page.js export default function Sidebar() { return <nav>Menu items here</nav> } // app/(content)/page.js export default function Content() { return <article>Main content here</article> }
This example shows a page with a sidebar and main content loaded in parallel routes. The sidebar has navigation links, and the content area has a heading and paragraph. They appear side by side.
// app/layout.js export default function RootLayout({ sidebar, content }) { return ( <html lang="en"> <body> <div style={{ display: 'flex', height: '100vh' }}> <aside style={{ width: '250px', backgroundColor: '#f0f0f0', padding: '1rem' }}> {sidebar} </aside> <main style={{ flex: 1, padding: '1rem' }}> {content} </main> </div> </body> </html> ) } // app/(sidebar)/page.js export default function Sidebar() { return ( <nav aria-label="Main navigation"> <ul> <li><a href="#home">Home</a></li> <li><a href="#about">About</a></li> <li><a href="#contact">Contact</a></li> </ul> </nav> ); } // app/(content)/page.js export default function Content() { return ( <article> <h1>Welcome to the content area</h1> <p>This section loads separately from the sidebar.</p> </article> ); }
Parallel routes improve user experience by loading parts of the page independently.
Use meaningful names for your parallel route folders inside parentheses.
Remember to add aria-label for accessibility on navigation elements.
Parallel routes let you show multiple parts of a page at once.
Use folder names with parentheses and destructure matching props in the layout to place them.
This helps make your app faster and easier to navigate.
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
