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.
- URL or navigation
- router config and guard
- component view
Explain the core concept and Angular data flow of Child Routes
Core syntax or pattern
// 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
- URL or navigation
// app-routing.module.tsChild Routes are used to build a nested routing structure.
- 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.
- component view
</div>Create profile, security, and billing child routes under an account layout and test the nested outlet, default redirect, and relative navigation.
- URL or navigation
- router config and guard
- 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.
// 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>(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
// 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
Quick quiz 2 / 3
Quick quiz 3 / 3
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