กลุ่มเส้นทางและเค้าโครงซ้อนกัน
จัดระเบียบโครงการตัวจัดเส้นทางแอปที่ซับซ้อนด้วยกลุ่มเส้นทาง เค้าโครงซ้อนกัน และไฟล์แม่แบบสำหรับส่วนติดต่อผู้ใช้ที่ใช้ร่วมกันและเฉพาะแต่ละส่วน
กลุ่มเส้นทางและเค้าโครงซ้อนกัน เป็นบทเรียน Next.js 15 Fullstack (App Router + Server Actions) ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Next.js 15 Fullstack (App Router + Server Actions) และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Next.js 15 Fullstack (App Router + Server Actions) มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
Why Organization Matters
As an app grows, the App Router lets you structure folders for shared UI without affecting the URL. Route groups and nested layouts are the main tools.
Nested Layouts Recap
Each folder can have a layout.tsx. Layouts nest: a section layout wraps its pages while the root layout wraps everything.
export default function DashboardLayout({ children }) {
return (<section><nav>Dashboard nav</nav>{children}</section>);
}Route Groups
Wrapping a folder name in parentheses, like (marketing), creates a route group. It organizes files but is omitted from the URL.
Multiple Root Layouts
Route groups let you have different top-level layouts — for example, one for marketing pages and another for the app — by giving each group its own layout.
app/
(marketing)/layout.tsx
(marketing)/page.tsx
(app)/layout.tsx
(app)/dashboard/page.tsxURLs Stay Clean
Because (marketing) does not appear in the path, app/(marketing)/page.tsx still serves the URL /, not /marketing.
Template vs Layout
A template.tsx is like a layout but creates a new instance on every navigation, resetting state — useful for enter animations or per-route effects.
export default function Template({ children }) {
return <div className="fade-in">{children}</div>;
}When to Use Template
Use a template when you need state or effects to re-run on each navigation; use a layout when you want shared UI and state to persist across navigations.
Organizing Without Routing
You can also use route groups purely to colocate related routes under one folder without adding a URL segment, keeping the codebase tidy.
Shared UI in Layouts
Put navigation, sidebars, and providers in the nearest layout so they persist and avoid re-rendering on navigation within that section.
Loading and Error per Section
Each segment, including grouped ones, can have its own loading.tsx and error.tsx, scoping fallback UI precisely.
Putting It Together
A typical app: a (marketing) group with a public layout, an (app) group with an authenticated layout, each nesting further section layouts.
Quick Check
What does wrapping a folder name in parentheses do?
Recap
You learned to structure apps with nested layouts for persistent shared UI, route groups (name) that organize without changing URLs and allow multiple root layouts, and templates that remount on navigation.
เรียนรู้ TypeScript ด้วย AI tutor — ฟรี
เขียนและเรียกใช้โค้ดจริงในเบราว์เซอร์ของคุณ รับความช่วยเหลือทันทีจาก AI tutor 24/7 และเรียนรู้ต่อจากที่คุณหยุดบนเว็บหรือในแอป
- คอร์ส
- 22
- บทเรียน
- 88
คำถามที่พบบ่อย
บทเรียน “กลุ่มเส้นทางและเค้าโครงซ้อนกัน” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “กลุ่มเส้นทางและเค้าโครงซ้อนกัน” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Next.js 15 Fullstack (App Router + Server Actions) ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Next.js 15 Fullstack (App Router + Server Actions) มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “กลุ่มเส้นทางและเค้าโครงซ้อนกัน”
จัดระเบียบโครงการตัวจัดเส้นทางแอปที่ซับซ้อนด้วยกลุ่มเส้นทาง เค้าโครงซ้อนกัน และไฟล์แม่แบบสำหรับส่วนติดต่อผู้ใช้ที่ใช้ร่วมกันและเฉพาะแต่ละส่วน คุณปฏิบัติ Next.js 15 Fullstack (App Router + Server Actions) ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Next.js 15 Fullstack (App Router + Server Actions) หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน Next.js 15 Fullstack (App Router + Server Actions) บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน
บทเรียน “กลุ่มเส้นทางและเค้าโครงซ้อนกัน” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Next.js 15 Fullstack (App Router + Server Actions) นี้ได้ไหม
ได้ บทเรียน Next.js 15 Fullstack (App Router + Server Actions) ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- เลย์เอาต์และคอมโพเนนต์หน้า
- เส้นทางแบบไดนามิกและพารามิเตอร์
- UI ระหว่างโหลดและ UI ข้อผิดพลาด
- กลุ่มเส้นทางและเค้าโครงซ้อนกัน