C.W.K.
Stream
Lesson 01 of 10 · published

File-Based Routing 기본

~20 min · routing, file system, page.tsx

Level 0Curious
0 XP0/68 lessons0/11 achievements
0/120 XP to next level120 XP to go0% complete

Folder 가 곧 route

app/ 안에서 폴더가 page.tsx 들고 있으면 route segment 가 돼. Folder nesting = route nesting:

FileURL
app/page.tsx/
app/about/page.tsx/about
app/blog/page.tsx/blog
app/blog/[slug]/page.tsx/blog/:slug
app/dashboard/settings/page.tsx/dashboard/settings

"page 가 public 으로 만든다" 룰

page.tsx 만 route 를 외부에 노출시켜. 같은 folder 의 다른 file 은 organizational — framework 가 load 는 하지만 URL 로 서빙 안 함. 그래서 URL 망가뜨리지 않고 component 를 route 옆에 놔둘 수 있어.

특수 file 어휘

File역할
page.tsxRoute UI — segment 를 public 으로 만드는 데 필수.
layout.tsx공유 UI wrap. Child navigation 너머로 살아남음.
loading.tsxSegment 의 Suspense fallback.
error.tsxError boundary (Client Component 여야 함).
not-found.tsx안에서 notFound() 부르면 render.
template.tsxLayout 같지만 navigation 마다 re-mount.
default.tsxHard navigation 시 parallel route slot 의 fallback.
route.tsAPI endpoint. 같은 folder 의 page.tsx 와 공존 불가.

Code

최소 page·tsx
// app/about/page.tsx → /about
export default function AboutPage() {
  return (
    <main className="prose mx-auto p-8">
      <h1>About</h1>
      <p>Default 로 server-rendered.</p>
    </main>
  );
}
Colocated component 는 route 안 됨·text
app/blog/
├── page.tsx               → /blog (public)
├── PostCard.tsx           → route 아님, 그냥 sibling
├── useFilters.ts          → route 아님
└── [slug]/
    ├── page.tsx           → /blog/:slug (public)
    └── ShareButton.tsx    → route 아님

External links

Exercise

5-route site 만들어: /, /about, /blog, /blog/[slug], /contact. /blog 에 post card 그리는 colocated component 박고, public URL 안 되는지 확인.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.