Thuta Learning
Vue.js
AdvancedWeb Developmentအခြေခံ

Routing with Vue Router

Vue.jsသင်ခန်းစာ 1725 မိနစ်

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

  • Route table တည်ဆောက်ရန်
  • RouterLink နှင့် RouterView သုံးရန်
  • Dynamic route ကိုနားလည်ရန်

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

Routing with Vue Router ကို ရိုးရိုးလေးနားလည်မယ်

Vue Router သည် Vue ၏ official client-side routing solution ဖြစ်သည်။ createRouter ဖြင့် URL path နှင့် component ကို map လုပ်ပြီး RouterView တွင် matched component ကို render လုပ်သည်။ RouterLink က full page reload မလုပ်ဘဲ history ကိုပြောင်းပေးသည်။

Problem → Why → Solution

ပြဿနာ — ဘာကြောင့် ဒီ concept လိုတာလဲ

App တွင် app.use(router) မလုပ်ခြင်း

ဖြစ်လေ့ရှိတဲ့အမှား

Route params နှင့် path ကို router.push ထဲတွင် မှားယွင်းပေါင်းသုံးခြင်း

Core Concept — အလုပ်လုပ်ပုံကိုနားလည်မယ်

Vue Router ဖြင့် URL မပြန်တင်ဘဲ view ပြောင်းသော single-page application navigation တည်ဆောက်မည်။

Mental Model
  1. URL / action
  2. Vue Router
  3. Component view

Route table တည်ဆောက်ရန်

အဓိက Syntax / Pattern

javascript
import { createRouter, createWebHistory } from 'vue-router'
import HomeView from './views/HomeView.vue'
import CourseView from './views/CourseView.vue'

export const router = createRouter({
  history: createWebHistory(),
  routes: [
    { path: '/', name: 'home', component: HomeView },
    { path: '/courses/:slug', name: 'course', component: CourseView, props: true }
  ]
})

Vue Router ဖြင့် URL မပြန်တင်ဘဲ view ပြောင်းသော single-page application navigation တည်ဆောက်မည်။

Code ကို အဆင့်လိုက်ဖတ်မယ်

  1. URL / actionimport { createRouter, createWebHistory } from 'vue-r...

    Vue Router သည် Vue ၏ official client-side routing solution ဖြစ်သည်။ createRouter ဖြင့် URL path နှင့် component ကို map လုပ်ပြီး RouterView တွင် matched component ကို render လုပ်သည်။ RouterLink က full page reload မလုပ်ဘဲ history ကိုပြောင်းပေးသည်။

  2. Vue Routerroutes: [

    Vue Router ဖြင့် URL မပြန်တင်ဘဲ view ပြောင်းသော single-page application navigation တည်ဆောက်မည်။

  3. Component view})

    Routing with Vue Router ကို example အသေးတစ်ခုနဲ့စပြီး normal, edge နဲ့ failure cases ကိုစစ်ပါ။

Execution Flow
  1. URL / action
  2. Vue Router
  3. Component view

Success

Route table တည်ဆောက်ရန်

Failure

App တွင် app.use(router) မလုပ်ခြင်း

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

Vue Router သည် Vue ၏ official client-side routing solution ဖြစ်သည်။ createRouter ဖြင့် URL path နှင့် component ကို map လုပ်ပြီး RouterView တွင် matched component ကို render လုပ်သည်။ RouterLink က full page reload မလုပ်ဘဲ history ကိုပြောင်းပေးသည်။

javascript
import { createRouter, createWebHistory } from 'vue-router'
import HomeView from './views/HomeView.vue'
import CourseView from './views/CourseView.vue'

export const router = createRouter({
  history: createWebHistory(),
  routes: [
    { path: '/', name: 'home', component: HomeView },
    { path: '/courses/:slug', name: 'course', component: CourseView, props: true }
  ]
})
You should see
/ → HomeView
/courses/vue → CourseView (slug: vue)

လက်တွေ့စမ်းကြည့်ရန်

Home, Courses နှင့် Course Detail routes သုံးခုတည်ဆောက်ပြီး navigation link ထည့်ပါ။

Vue Router — Getting Started — Vue Router

Real-world usage

လက်တွေ့ Project မှာ ဘယ်လိုသုံးမလဲ

Routing with Vue Router ကို example အသေးတစ်ခုနဲ့စပြီး normal, edge နဲ့ failure cases ကိုစစ်ပါ။

Mini challenge

ကိုယ်တိုင်တည်ဆောက်ကြည့်ပါ

Home, Courses နှင့် Course Detail routes သုံးခုတည်ဆောက်ပြီး navigation link ထည့်ပါ။

  • Example ကို copy မလုပ်ဘဲ ပြန်ရေးပါ
  • Normal input နဲ့ edge case စမ်းပါ
  • Run မလုပ်မီ compiler/output result ကိုခန့်မှန်းပါ
javascript
import { createRouter, createWebHistory } from 'vue-router'
import HomeView from './views/HomeView.vue'
import CourseView from './views/CourseView.vue'

export const router = createRouter({
  history: createWebHistory(),
  routes: [
    { path: '/', name: 'home', component: HomeView },
    { path: '/courses/:slug', name: 'course', component: CourseView, props: true }
  ]
})

ရလဒ်: Route table တည်ဆောက်ရန်

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

Routing with Vue Router ကို example အသေးတစ်ခုနဲ့စပြီး normal, edge နဲ့ failure cases ကိုစစ်ပါ။

Quick Quiz 1 / 3

Routing with Vue Router ရဲ့ အဓိကသဘောတရားက ဘာလဲ။

Quick Quiz 2 / 3

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

Quick Quiz 3 / 3

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

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

  • URL / action → Vue Router → Component view
  • Vue Router ဖြင့် URL မပြန်တင်ဘဲ view ပြောင်းသော single-page application navigation တည်ဆောက်မည်။
  • App တွင် app.use(router) မလုပ်ခြင်း
  • Routing with Vue Router ကို example အသေးတစ်ခုနဲ့စပြီး normal, edge နဲ့ failure cases ကိုစစ်ပါ။

Vue Router — Getting Started — Vue Router

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

  • App တွင် app.use(router) မလုပ်ခြင်း
  • Route params နှင့် path ကို router.push ထဲတွင် မှားယွင်းပေါင်းသုံးခြင်း

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

Home, Courses နှင့် Course Detail routes သုံးခုတည်ဆောက်ပြီး navigation link ထည့်ပါ။

အလုပ်ဖြစ်ကြောင်း ဒီလိုသိမယ်: / → HomeView /courses/vue → CourseView (slug: vue)

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

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

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

Routing with Vue Router | Thuta Learning