Menu

Parallel Routes

Lesson 1: Parallel Routes

What are parallel routes?

Parallel routes let one layout render several pages at the same time, each from its own folder called a slot. Slots are named with an @ prefix.

Use case Slots
Dashboard with independent panels @progress, @recommendations
Different views by role @student, @instructor
A modal alongside the main page @modal (Lesson 2)

Example

app/dashboard/
├─ layout.tsx
├─ page.tsx              # children
├─ default.tsx
├─ @progress/
│  ├─ page.tsx
│  ├─ loading.tsx
│  └─ default.tsx
└─ @recommendations/
   ├─ page.tsx
   └─ default.tsx
// app/dashboard/layout.tsx
export default function DashboardLayout({
  children,
  progress,
  recommendations,
}: {
  children: React.ReactNode;
  progress: React.ReactNode;
  recommendations: React.ReactNode;
}) {
  return (
    <div className="grid grid-cols-3 gap-6">
      <section className="col-span-2">{children}{progress}</section>
      <aside>{recommendations}</aside>
    </div>
  );
}
// app/dashboard/@recommendations/default.tsx
export default function Default() {
  return null;
}

How it works

  • Each slot is passed to the layout as a prop with the same name (@progress → progress).
  • Slots do not change the URL. /dashboard renders all three.
  • Each slot can have its own loading.tsx and error.tsx, so a slow or failing panel does not affect the others.
  • default.tsx tells Next.js what to show in a slot when the current URL has no matching page in it, such as after a full page reload on a sub-route.
  • Since Next.js 16, every slot must have a **default.tsx**; the build fails without one. Return null or call notFound() to keep the old behaviour.

Conditional slots by role:

export default async function Layout({ student, instructor }: { student: React.ReactNode; instructor: React.ReactNode }) {
  const user = await getCurrentUser();
  return user.role === 'instructor' ? instructor : student;
}

Common mistakes

Mistake Effect Fix
Missing default.tsx in a slot Build fails in Next.js 16 Add one to every slot (and the parent if needed)
Expecting @slot in the URL 404 errors Slots never appear in URLs
Forgetting to render a slot prop Slot content never shows Render every slot in the layout

Key takeaways

  • Parallel routes render independent sections, each with its own loading and error UI.
  • Every slot needs a default.tsx in Next.js 16.

Try it: Build the LearnHub dashboard with @progress and @recommendations slots, and give the progress slot a 2-second loading state.


Nextjs Tutorial

J

Jebasta





Get in Touch For Details