📖 Scenario: You are creating a simple Next.js app that shows two different sections side by side: a Profile and a Settings panel. Both should be visible at the same time using parallel routes.
🎯 Goal: Build a Next.js app with parallel routes to display profile and settings components side by side on the same page.
📋 What You'll Learn
Create a main layout with two parallel route outlets named profile and settings
Create a profile route that shows user profile information
Create a settings route that shows user settings options
Use Next.js App Router conventions with layout.js and page.js files
Ensure the parallel routes render side by side in a responsive layout
💡 Why This Matters
🌍 Real World
Parallel routes let you show multiple views or panels at once, like a dashboard with different widgets visible side by side.
💼 Career
Understanding parallel routes is useful for building complex user interfaces in Next.js apps, a common skill for frontend developers.
Progress0 / 4 steps
1
Set up the main layout with parallel route slots
Create a layout.js file inside the app directory. Inside it, create a React component that returns a div with two section elements. Each section should render a Slot component with names profile and settings respectively. Import Slot from next/navigation.
NextJS
Hint
Remember to import Slot from next/navigation and use it with the name prop for parallel routes.
2
Create the profile parallel route page
Inside the app directory, create a folder named @profile. Inside it, create a page.js file. Export a React component that returns a div with the text User Profile Section.
NextJS
Hint
Create a simple React component that returns a div with the exact text User Profile Section.
3
Create the settings parallel route page
Inside the app directory, create a folder named @settings. Inside it, create a page.js file. Export a React component that returns a div with the text User Settings Section.
NextJS
Hint
Create a React component that returns a div with the exact text User Settings Section.
4
Add the main page to render both parallel routes
Inside the app directory, create a page.js file. Export a React component that returns a div with the text Main Dashboard. This page will render alongside the parallel routes defined in the layout.
NextJS
Hint
Create a simple React component that returns a div with the text Main Dashboard.
Practice
(1/5)
1. What is the main purpose of parallel routes in Next.js?
easy
A. To disable navigation between pages
B. To load pages sequentially one after another
C. To replace client-side routing with server-side only
D. To display multiple parts of a page simultaneously
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 D
Quick Check:
Parallel routes = show multiple parts [OK]
Hint: Parallel routes show multiple page parts at once [OK]
Common Mistakes:
Thinking parallel routes load pages one after another
Confusing parallel routes with disabling navigation
A. Because Slot must be imported from 'next/navigation' as a named import
B. Because <Slot /> should be self-closing JSX tags, not string literals
C. Because parallel routes cannot use Slot components
D. Because Slot requires a default export, not named
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 B
Quick Check:
JSX tags must not be strings [OK]
Hint: Use JSX tags, not strings, for [OK]
Common Mistakes:
Writing JSX tags as strings inside return
Importing Slot incorrectly
Thinking Slot can't be used in parallel routes
5. You want to create a page with a sidebar and main content using parallel routes. Which folder structure and code snippet correctly implements this in Next.js?