Thuta Learning
ရှာဖွေရန်
ExercisesWeb Developmentintermediate

Practice Set 1 — Routing, Layout နှင့် Component အခြေခံ လေ့ကျင့်ခန်းများ

စိတ်လျှော့ပါ။ ဒီခန်းကို စာအုပ်လိုမဟုတ်ဘဲ စကားပြောသလိုပဲ၊ နားလည်လွယ်အောင် ရှင်းပါမယ်။

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

  • Practice Set 1 — Routing, Layout နှင့် Component အခြေခံ လေ့ကျင့်ခန်းများ ကို ကိုယ်တိုင် လေ့ကျင့်ကြည့်မယ်
  • သင်ခဲ့ပြီးသား skill တွေကို practice လုပ်ပြီး ခိုင်မာအောင်လုပ်မယ်
  • အမှားရှာ၊ ပြင်တတ်၊ ကိုယ်တိုင် check လုပ်တတ်မယ်

ခဏလေး ဒီလိုပဲ စဉ်းစားကြည့်

ဒီ practice set က tutorial ရဲ့ အစောပိုင်း chapter တွေမှာ သင်ခဲ့တဲ့ routing၊ layout၊ component boundary skill တွေကို အသစ်ဘာမှမသင်ဘဲ ကိုယ်တိုင်ပြန်လက်တွေ့လုပ်ကြည့်ဖို့ ရည်ရွယ်ပါတယ်။ Task တစ်ခုစီက ခဏတိုလေးအတွင်း ပြီးနိုင်တဲ့ scope သေးငယ်ပါတယ်။ Solution တစ်ခုတည်းရှိတာမဟုတ်ပါဘူး — အရေးကြီးတာက concept ကို ကိုယ်ပိုင် code နဲ့ ပြန်ရေးနိုင်ဖို့ပါ။

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

(1) app/about/page.tsx static route တစ်ခု ဖန်တီးပြီး root layout ထဲက nav မှာ Link ထည့်ပါ။ (2) app/products/[slug]/page.tsx dynamic route ဖန်တီးပြီး params.slug ကို heading အဖြစ်ပြပါ။ (3) app/(marketing)/ route group တစ်ခုဖန်တီးပြီး ၎င်းအောက်မှာ layout သီးခြားတစ်ခု (background color ကွဲတဲ့) ထည့်ပါ — URL path ပေါ်မှာ group folder အမည်မပါဘဲ ကျန်ရစ်ကြောင်း confirm လုပ်ပါ။ (4) button click count ပြထားတဲ့ Counter component တစ်ခုကို "use client" directive နဲ့ ဖန်တီးပြီး Server Component ဖြစ်တဲ့ page ထဲမှာ import လုပ်ကြည့်ပါ.

Code နမူနာ

tsx
// Task 4 starter skeleton — components/Counter.tsx
"use client";
import { useState } from "react";

export default function Counter() {
  const [count, setCount] = useState(0);
  return (
    <button onClick={() => setCount(count + 1)}>
      Clicked {count} times
    </button>
  );
}

// app/products/[slug]/page.tsx skeleton
export default function ProductPage({ params }: { params: { slug: string } }) {
  return <h2>Product: {params.slug}</h2>;
}
You should see
Task လေးခုစလုံးပြီးရင် app ထဲမှာ route အသစ် 3 ခုနဲ့ interactive client component တစ်ခု ပေါင်းစပ်အလုပ်လုပ်နေတာ တွေ့ရပါလိမ့်မယ်။

၅ မိနစ် စမ်းကြည့်

Task (2) ရဲ့ dynamic route ကို /products/abc, /products/123 စတဲ့ slug မတူတဲ့ URL 2-3 ခုနဲ့ browser ထဲစမ်းကြည့်ပြီး heading ပြောင်းသွားတာကို 5 မိနစ်အတွင်း confirm လုပ်ပါ။

သတိလေးတစ်ချက်

task တစ်ခုစီကို ပြီးတိုင်း dev server error console ကို check ပါ — TypeScript type error တွေက build မှာမှမတွေ့ခင် terminal ထဲမှာ ချက်ချင်းပေါ်တတ်ပါတယ်။

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

  • route group folder name ကို parenthesis (marketing) မပါဘဲ marketing လို့ရိုက်မိလို့ URL path ထဲမှာ /marketing/ ပါသွားတတ်ပါတယ်
  • Counter component ထိပ်ဆုံးမှာ "use client" directive ထည့်ဖို့ မေ့သွားလို့ useState က server မှာ error တက်တတ်ပါတယ်

အခု ကိုယ်တိုင် စမ်းကြည့်

Task (2) ရဲ့ dynamic route ကို /products/abc, /products/123 စတဲ့ slug မတူတဲ့ URL 2-3 ခုနဲ့ browser ထဲစမ်းကြည့်ပြီး heading ပြောင်းသွားတာကို 5 မိနစ်အတွင်း confirm လုပ်ပါ။

You'll know it worked when: Task လေးခုစလုံးပြီးရင် app ထဲမှာ route အသစ် 3 ခုနဲ့ interactive client component တစ်ခု ပေါင်းစပ်အလုပ်လုပ်နေတာ တွေ့ရပါလိမ့်မယ်။

Practice Set 1 — Routing, Layout နှင့် Component အခြေခံ လေ့ကျင့်ခန်းများ | Thuta Learning