Thuta Learning
Angular
AdvancedWeb DevelopmentIntermediate

Child Routes

AngularLesson 3425 min

What you'll walk away with

  • Explain the core concept and Angular data flow of Child Routes
  • Run the example, predict its state and UI, and test edge and error cases
  • Apply a typed safe pattern in a real project and recognize common pitfalls

Explain it simply

Child Routes, in plain language

Child Routes are used to build a nested routing structure.

Problem → Why → Solution

The problem — why this concept matters

A child-route configuration cannot render without the corresponding nested router-outlet.

A common mistake

One happy-path result does not prove the feature works; empty, loading, error, and cleanup behavior need explicit tests.

Core concept — understand how it works

Child routes express feature layouts, nested URLs, and outlet ownership. A parent can own shared shell, data, or guards while children represent overview, edit, and history views. Test relative links, default-child redirects, inherited route data, and component reuse or destruction.

Mental model
  1. URL or navigation
  2. router config and guard
  3. component view

Explain the core concept and Angular data flow of Child Routes

Core syntax or pattern

typescript
// app-routing.module.ts
const routes: Routes = [
  {
    path: 'dashboard',
    component: DashboardComponent,
    children: [
      { path: '', redirectTo: 'overview', pathMatch: 'full' },
      { path: 'overview', component: OverviewComponent },
      { path: 'stats', component: StatsComponent },
      { path: 'settings', component: SettingsComponent }
    ]
  }
];

// dashboard.component.html
<div class="dashboard">
  <nav>
    <a routerLink="overview">Overview</a>
    <a routerLink="stats">Statistics</a>
    <a routerLink="settings">Settings</a>
  </nav>
  
  <!-- Child routes render here -->
  <router-outlet></router-outlet>
</div>

Child routes express feature layouts, nested URLs, and outlet ownership. A parent can own shared shell, data, or guards while children represent overview, edit, and history views. Test relative links, default-child redirects, inherited route data, and component reuse or destruction.

Read the code step by step

  1. URL or navigation// app-routing.module.ts

    Child Routes are used to build a nested routing structure.

  2. router config and guard}

    Child routes express feature layouts, nested URLs, and outlet ownership. A parent can own shared shell, data, or guards while children represent overview, edit, and history views. Test relative links, default-child redirects, inherited route data, and component reuse or destruction.

  3. component view</div>

    Create profile, security, and billing child routes under an account layout and test the nested outlet, default redirect, and relative navigation.

Execution flow
  1. URL or navigation
  2. router config and guard
  3. component view

Success

Explain the core concept and Angular data flow of Child Routes

Failure

A child-route configuration cannot render without the corresponding nested router-outlet.

Child Routes are used to build a nested routing structure.

typescript
// app-routing.module.ts
const routes: Routes = [
  {
    path: 'dashboard',
    component: DashboardComponent,
    children: [
      { path: '', redirectTo: 'overview', pathMatch: 'full' },
      { path: 'overview', component: OverviewComponent },
      { path: 'stats', component: StatsComponent },
      { path: 'settings', component: SettingsComponent }
    ]
  }
];

// dashboard.component.html
<div class="dashboard">
  <nav>
    <a routerLink="overview">Overview</a>
    <a routerLink="stats">Statistics</a>
    <a routerLink="settings">Settings</a>
  </nav>
  
  <!-- Child routes render here -->
  <router-outlet></router-outlet>
</div>
You should see
(Nested routes like /dashboard/overview and /dashboard/stats will work)

Real-world usage

How to apply it in a real project

Create profile, security, and billing child routes under an account layout and test the nested outlet, default redirect, and relative navigation.

Mini challenge

Build it yourself

Rebuild the Child Routes example without copying it. Add two normal states, one edge case, and one failure state, and write the expected UI and state transition before running it.

  • Rebuild the example without copying it
  • Test a normal input and an edge case
  • Predict the compiler or output result before running it
typescript
// app-routing.module.ts
const routes: Routes = [
  {
    path: 'dashboard',
    component: DashboardComponent,
    children: [
      { path: '', redirectTo: 'overview', pathMatch: 'full' },
      { path: 'overview', component: OverviewComponent },
      { path: 'stats', component: StatsComponent },
      { path: 'settings', component: SettingsComponent }
    ]
  }
];

// dashboard.component.html
<div class="dashboard">
  <nav>
    <a routerLink="overview">Overview</a>
    <a routerLink="stats">Statistics</a>
    <a routerLink="settings">Settings</a>
  </nav>
  
  <!-- Child routes render here -->
  <router-outlet></router-outlet>
</div>

Expected: Explain the core concept and Angular data flow of Child Routes

Show hint

Create profile, security, and billing child routes under an account layout and test the nested outlet, default redirect, and relative navigation.

Quick quiz 1 / 3

What best describes the core idea of Child Routes?

Quick quiz 2 / 3

Which mistake should you avoid first?

Quick quiz 3 / 3

How should this be applied in a real project?

What to remember

  • URL or navigation → router config and guard → component view
  • Child routes express feature layouts, nested URLs, and outlet ownership. A parent can own shared shell, data, or guards while children represent overview, edit, and history views. Test relative links, default-child redirects, inherited route data, and component reuse or destruction.
  • A child-route configuration cannot render without the corresponding nested router-outlet.
  • Create profile, security, and billing child routes under an account layout and test the nested outlet, default redirect, and relative navigation.

Angular — Routing — Angular

Easy traps

  • A child-route configuration cannot render without the corresponding nested router-outlet.
  • One happy-path result does not prove the feature works; empty, loading, error, and cleanup behavior need explicit tests.

Hands-on Exercise

Rebuild the Child Routes example without copying it. Add two normal states, one edge case, and one failure state, and write the expected UI and state transition before running it.

You'll know it worked when: (Nested routes like /dashboard/overview and /dashboard/stats will work)

Updated on

Progress is saved only in this browser on this device. It isn't synced to other devices.

Report a problem with this lessonOpens your email app with this lesson's address filled in — nothing is sent until you send it.

Child Routes | Thuta Learning