Thuta Learning
Angular
AdvancedWeb Developmentအလယ်အလတ်

Child Routes

Angularသင်ခန်းစာ 3425 မိနစ်

ဒီခန်းပြီးရင် ဘာတတ်သွားမလဲ

  • Child Routes ရဲ့ core concept နဲ့ Angular data flow ကိုရှင်းပြနိုင်ရန်
  • နမူနာ UI ကို run၊ state/output ခန့်မှန်းပြီး edge/error cases စမ်းနိုင်ရန်
  • လက်တွေ့ project တွင် typed safe pattern နဲ့ common pitfalls ကိုခွဲသိနိုင်ရန်

ရိုးရိုးလေး ရှင်းပြမယ်

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 ကိုရှင်းရှင်းလင်းလင်းစမ်းပါ။

Mental Model
  1. URL / navigation
  2. Router config + guard
  3. Component view

Child Routes ရဲ့ core concept နဲ့ Angular data flow ကိုရှင်းပြနိုင်ရန်

အဓိက Syntax / 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 က 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 ကို အဆင့်လိုက်ဖတ်မယ်

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

    Child Routes များသည် nested routing structure တစ်ခု တည်ဆောက်ရန် အသုံးပြုသည်။

  2. 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 ကိုရှင်းရှင်းလင်းလင်းစမ်းပါ။

  3. Component view</div>

    Account layout အောက် profile/security/billing child routes တည်ဆောက်ပြီး nested outlet, default redirect နဲ့ relative navigation ကိုစမ်းပါ။

Execution Flow
  1. URL / navigation
  2. Router config + guard
  3. Component view

Success

Child Routes ရဲ့ core concept နဲ့ Angular data flow ကိုရှင်းပြနိုင်ရန်

Failure

Child component ရဲ့ `<router-outlet>` မထည့်ဘဲ config ပဲရေးလျှင် nested content render မဖြစ်ပါ။

Child Routes များသည် 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
(/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 ကိုခန့်မှန်းပါ
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 ရဲ့ core concept နဲ့ Angular data flow ကိုရှင်းပြနိုင်ရန်

အရိပ်အမြွက် ကြည့်ရန်

Account layout အောက် profile/security/billing child routes တည်ဆောက်ပြီး nested outlet, default redirect နဲ့ relative navigation ကိုစမ်းပါ။

Quick Quiz 1 / 3

Child Routes ရဲ့ အဓိကသဘောတရားက ဘာလဲ။

Quick Quiz 2 / 3

ဘယ်အမှားကို အရင်ဆုံးရှောင်သင့်လဲ။

Quick Quiz 3 / 3

Real project မှာ ဘယ်လိုအသုံးချသင့်လဲ။

ဒီသင်ခန်းစာမှာ မှတ်ထားရမယ့်အချက်များ

  • 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

ဒီနေရာမှာ လူအများမှားတတ်တယ်

  • Child component ရဲ့ `<router-outlet>` မထည့်ဘဲ config ပဲရေးလျှင် nested content render မဖြစ်ပါ။
  • Happy path တစ်ခုအောင်တာနဲ့ feature မှန်ပြီဟုယူဆခြင်းက empty, loading, error နဲ့ cleanup bugs များကိုလွတ်စေနိုင်ပါတယ်။

လက်တွေ့လေ့ကျင့်ခန်း

Child Routes နမူနာကို copy မလုပ်ဘဲ ကိုယ်တိုင်ပြန်ရေးပါ။ Normal state နှစ်ခု၊ edge case တစ်ခုနှင့် failure state တစ်ခုထည့်ပြီး expected UI နဲ့ state transition ကိုမ run မီရေးထားပါ။

အလုပ်ဖြစ်ကြောင်း ဒီလိုသိမယ်: (/dashboard/overview, /dashboard/stats စသည်ဖြင့် nested routes များ အလုပ်လုပ်မည်)

နောက်ဆုံးပြင်ဆင်ရက်

Progress ကို ဤ browser (ဤစက်) တွင်သာ သိမ်းထားပါသည်။ အခြားစက်များနှင့် sync မလုပ်ပါ။

ဤသင်ခန်းစာတွင် အမှားတွေ့ပါက အကြောင်းကြားရန်သင့် email app ကို ဤသင်ခန်းစာလိပ်စာ ဖြည့်ပြီးသားဖြင့် ဖွင့်ပေးပါမည် — သင်ကိုယ်တိုင် ပို့မှသာ ပို့မည်ဖြစ်သည်။

Child Routes | Thuta Learning