Next.jsHard
What are parallel routes in Next.js?
Parallel routes let one layout render several independent pages at the same time using named slots. A folder prefixed with @, such as app/dashboard/@analytics, becomes a prop (analytics) on the parent layout, alongside children.
How it works
app/dashboard/@team/page.tsxandapp/dashboard/@analytics/page.tsxare passed toapp/dashboard/layout.tsxasteamandanalyticsprops.- Slots do not change the URL.
childrenis an implicit slot (@children). - Each slot can have its own
loading.tsxanderror.tsx, so one panel can stream or fail independently. - Slots can be shown conditionally, for example rendering
@adminor@userdepending on the role.
default.tsx is required (Next.js 16)
On a full page load, Next.js needs a page for every slot for the current URL. If a slot has no match, it renders that slot's default.tsx. Since Next.js 16, every slot must have an explicit default.tsx, or the build fails. Return null or call notFound() to keep the old behavior.
On soft (client) navigation, a slot without a match keeps showing its previous page.
Common uses
- Dashboards with independent panels.
- Modals combined with intercepting routes:
@modal/(.)photo/[id]shows a modal on soft navigation, while a direct visit renders the full photo page. - Split views and tabbed sub-navigation inside a slot.
Pitfalls
- Forgetting
default.tsxcauses 404s on refresh or build failures. - Slots are not route segments:
@analytics/page.tsxdoes not create/analytics. - Use
useSelectedLayoutSegment("analytics")to read the active segment of a slot.
Code example
tsx
1// app/dashboard/layout.tsx2export default function DashboardLayout({3 children,4 team,5 analytics,6}: LayoutProps<"/dashboard">) {7 return (8 <div className="grid grid-cols-2 gap-4">9 <section className="col-span-2">{children}</section>10 <section>{team}</section> {/* app/dashboard/@team/page.tsx */}11 <section>{analytics}</section> {/* app/dashboard/@analytics/page.tsx */}12 </div>13 );14}1516// app/dashboard/@analytics/loading.tsx - streams independently17// export default function Loading() { return <p>Loading charts…</p>; }1819// app/dashboard/@analytics/default.tsx - REQUIRED since Next.js 1620export function Default() {21 return null; // or notFound()22}2324// app/dashboard/@team/page.tsx25// export default async function Team() {26// const members = await getMembers();27// return <ul>{members.map((m) => <li key={m.id}>{m.name}</li>)}</ul>;28// }
Practice this question
Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the Next.js set.