routes/
ββ home.tsx
ββ login.tsx
ββ create-account.tsx
ββ profile.tsx
μ΄ νμΌλ€μ 곡ν΅μ μ λ³΄ν΅ μ΄λ° ννμ λλ€:
// routes/login.tsx
export default function Login() {
return (
<div>
<h1>λ‘κ·ΈμΈ</h1>
{/* μ¬λ¬ μ»΄ν¬λνΈ μ‘°ν© */}
</div>
);
}
URLκ³Ό 1:1 λμ
/login β login.tsx/profile β profile.tsxλ³΄ν΅ λΌμ°ν°μμ μ§μ importλ¨
ν νλ©΄ μ 체λ₯Ό μ± μμ§
λ€λ₯Έ νμ΄μ§μμ μ¬μ¬μ©λλ κ²½μ°λ κ±°μ μμ
π κ·Έλμ
β
βλΌμ°νΈ = κ°κ°μ νμ΄μ§β
λΌκ³ μ΄ν΄νμ
λ λ©λλ€.
components/
ββ layout.tsx
μλ₯Ό λ€λ©΄:
// components/layout.tsx
export default function Layout({ children }) {
return (
<>
<Header />
<main>{children}</main>
<Footer />
</>
);
}
π μ΄ Layoutμ
κ·Έλμ λ§μνμ νν μ€ μ΄ λΆλΆμ΄ μ νν©λλ€ π
νμ΄μ§μ μ½μ λλ ꡬμ±μμ
μ΄λμλ μνλ©΄ νμ΄μ§ μ΄λλ μΆκ°ν μ μλ μμ
βοΈ λ§μ΅λλ€.
λ³΄ν΅ κ΅¬μ‘°λ μ΄λ κ² νλ¬κ°λλ€:
main.tsx
ββ App.tsx
ββ Router
ββ routes/*
// App.tsx μμ
<BrowserRouter>
<Layout>
<Routes>
<Route path="/" element={<Home />} />
<Route path="/login" element={<Login />} />
</Routes>
</Layout>
</BrowserRouter>
μ¬κΈ°μ ν΅μ¬:
routes = κ° λ°©
components = κ°κ΅¬
π λ°©μ μ£Όμ(URL)κ° μμ§λ§
π κ°κ΅¬λ μ£Όμκ° μμ΅λλ€
β μ΄ νμΌμ μ΄λμ λ¬μΌ ν κΉ?
URLλ‘ μ§μ μ κ·Όν΄μΌ νλ?
λ€λ₯Έ νμ΄μ§μμλ μ¬μ¬μ©λ κ°λ₯μ±μ΄ μλ?
Routerμ λ±λ‘λ κΉ?
β
λ€, μ§κΈ ꡬ쑰λ μμ£Ό κ΅κ³Όμμ μΈ μ΄κΈ° ꡬ쑰μ
λλ€.
νΉν layout.tsxλ₯Ό componentsμ λ κ²λ μ νν©λλ€.
λμ€μ νλ‘μ νΈ μ»€μ§λ©΄ λ³΄ν΅ μ΄λ κ² νμ₯λ©λλ€:
components/
ββ layout/
ββ ui/
ββ auth/
ββ common/
routes/
ββ home.tsx
ββ login.tsx
ββ profile.tsx