ရိုးရိုးလေး ရှင်းပြမယ်
Child Routes ကို ရိုးရိုးလေးနားလည်မယ်
Child Routes များသည် nested routing structure တစ်ခု တည်ဆောက်ရန် အသုံးပြုသည်။
Problem → Why → Solution
ပြဿနာ — ဘာကြောင့် ဒီ concept လိုတာလဲ
Child component ရဲ့ `<router-outlet>` မထည့်ဘဲ config ပဲရေးလျှင် nested content render မဖြစ်ပါ။
ဖြစ်လေ့ရှိတဲ့အမှား
Happy path တစ်ခုအောင်တာနဲ့ feature မှန်ပြီဟုယူဆခြင်းက empty, loading, error နဲ့ cleanup bugs များကိုလွတ်စေနိုင်ပါတယ်။
Core Concept — အလုပ်လုပ်ပုံကိုနားလည်မယ်
Child routes က feature layout, nested URL နဲ့ nested outlet ownership ကိုဖော်ပြပါတယ်။ Parent route က shared shell/data/guards ပိုင်နိုင်ပြီး child path တွေက overview/edit/history လို subviews ခွဲပါတယ်။ Relative links, default child redirect, route data inheritance နဲ့ destroy/reuse behavior ကိုရှင်းရှင်းလင်းလင်းစမ်းပါ။
- URL / navigation
- Router config + guard
- Component view
Child Routes ရဲ့ core concept နဲ့ Angular data flow ကိုရှင်းပြနိုင်ရန်
အဓိက Syntax / 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 က feature layout, nested URL နဲ့ nested outlet ownership ကိုဖော်ပြပါတယ်။ Parent route က shared shell/data/guards ပိုင်နိုင်ပြီး child path တွေက overview/edit/history လို subviews ခွဲပါတယ်။ Relative links, default child redirect, route data inheritance နဲ့ destroy/reuse behavior ကိုရှင်းရှင်းလင်းလင်းစမ်းပါ။
Code ကို အဆင့်လိုက်ဖတ်မယ်
- URL / navigation
// app-routing.module.tsChild Routes များသည် nested routing structure တစ်ခု တည်ဆောက်ရန် အသုံးပြုသည်။
- Router config + guard
}Child routes က feature layout, nested URL နဲ့ nested outlet ownership ကိုဖော်ပြပါတယ်။ Parent route က shared shell/data/guards ပိုင်နိုင်ပြီး child path တွေက overview/edit/history လို subviews ခွဲပါတယ်။ Relative links, default child redirect, route data inheritance နဲ့ destroy/reuse behavior ကိုရှင်းရှင်းလင်းလင်းစမ်းပါ။
- Component view
</div>Account layout အောက် profile/security/billing child routes တည်ဆောက်ပြီး nested outlet, default redirect နဲ့ relative navigation ကိုစမ်းပါ။
- URL / navigation
- Router config + guard
- Component view
Success
Child Routes ရဲ့ core concept နဲ့ Angular data flow ကိုရှင်းပြနိုင်ရန်
Failure
Child component ရဲ့ `<router-outlet>` မထည့်ဘဲ config ပဲရေးလျှင် nested content render မဖြစ်ပါ။
Child Routes များသည် 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>(/dashboard/overview, /dashboard/stats စသည်ဖြင့် nested routes များ အလုပ်လုပ်မည်)Real-world usage
လက်တွေ့ Project မှာ ဘယ်လိုသုံးမလဲ
Account layout အောက် profile/security/billing child routes တည်ဆောက်ပြီး nested outlet, default redirect နဲ့ relative navigation ကိုစမ်းပါ။
Mini challenge
ကိုယ်တိုင်တည်ဆောက်ကြည့်ပါ
Child Routes နမူနာကို copy မလုပ်ဘဲ ကိုယ်တိုင်ပြန်ရေးပါ။ Normal state နှစ်ခု၊ edge case တစ်ခုနှင့် failure state တစ်ခုထည့်ပြီး expected UI နဲ့ state transition ကိုမ run မီရေးထားပါ။
- Example ကို copy မလုပ်ဘဲ ပြန်ရေးပါ
- Normal input နဲ့ edge case စမ်းပါ
- Run မလုပ်မီ compiler/output result ကိုခန့်မှန်းပါ
// 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 ရဲ့ core concept နဲ့ Angular data flow ကိုရှင်းပြနိုင်ရန်
အရိပ်အမြွက် ကြည့်ရန်
Account layout အောက် profile/security/billing child routes တည်ဆောက်ပြီး nested outlet, default redirect နဲ့ relative navigation ကိုစမ်းပါ။
Quick Quiz 1 / 3
Quick Quiz 2 / 3
Quick Quiz 3 / 3
ဒီသင်ခန်းစာမှာ မှတ်ထားရမယ့်အချက်များ
- URL / navigation → Router config + guard → Component view
- Child routes က feature layout, nested URL နဲ့ nested outlet ownership ကိုဖော်ပြပါတယ်။ Parent route က shared shell/data/guards ပိုင်နိုင်ပြီး child path တွေက overview/edit/history လို subviews ခွဲပါတယ်။ Relative links, default child redirect, route data inheritance နဲ့ destroy/reuse behavior ကိုရှင်းရှင်းလင်းလင်းစမ်းပါ။
- Child component ရဲ့ `<router-outlet>` မထည့်ဘဲ config ပဲရေးလျှင် nested content render မဖြစ်ပါ။
- Account layout အောက် profile/security/billing child routes တည်ဆောက်ပြီး nested outlet, default redirect နဲ့ relative navigation ကိုစမ်းပါ။
Angular — Routing — Angular