π μμ½
μμ μκ°: 3μκ°λ°? 4μκ°?
β
νλ‘μ νΈ ν΄λ ꡬ쑰 μ 리
β
React Routerλ‘ νμ΄μ§ μ΄λ κ°λ₯νκ² λ§λ€κΈ°
β
λ€λΉκ²μ΄μ
λ°(Navbar) μ μ
β
λ‘κ·ΈμΈ νμ΄μ§ UI ꡬμ±
π ν΄λ ꡬ쑰
/src
βββ /components # μ¬μ¬μ© κ°λ₯ν UI μ»΄ν¬λνΈ
β βββ Navbar.tsx
β βββ Button.tsx
β βββ Card.tsx
β βββ Footer.tsx
βββ /pages # νμ΄μ§ λ¨μ νμΌ
β βββ Home.tsx
β βββ Upload.tsx
β βββ PostList.tsx
β βββ Gallery.tsx
β βββ Login.tsx
βββ App.tsx
βββ main.tsx
βββ index.css
βββ vite.config.ts
π React Router μ μ©
react-router-dom μ€μΉ
npm install react-router-dom
νμ μ§μ ν¨ν€μ§ μ€μΉ
(react-router-domμ JavaScript κΈ°λ° λΌμ΄λΈλ¬λ¦¬μ΄κΈ° λλ¬Έμ TypeScriptκ° μ체μ μΌλ‘ νμ
μ μμ§ λͺ»ν¨.
@types/react-router-domμ μ€μΉνλ©΄ React Routerμ νμ
μ 보(μ: Route, Link, useNavigate λ±)λ₯Ό TypeScriptμμ μΈμ)
npm install @types/react-router-dom --save-dev
μ΄λ κ² κ°λ¨ν νμ΄μ§ ꡬλΆμ ν΄μ£Όμλ€.
function App() {
return (
<Router>
<div className="flex flex-col min-h-screen min-w-screen">
<Navbar />
<div className="flex-grow">
<Routes>
<Route path="/" element={<Home />} />
<Route path="/events" element={<EventList />} />
<Route path="/login" element={<Login />} />
</Routes>
</div>
<Footer />
</div>
</Router>
);
}
π λ€λΉκ²μ΄μ , λ‘κ·ΈμΈ UI ꡬμ±
λ€λΉκ²μ΄μ μ½λ
import { Link } from "react-router-dom";
const Navbar = () => {
return (
<nav className="w-full bg-blue-300 h-14 px-4 text-white flex justify-between items-center">
<h1 className="text-xl font-bold">Resho</h1>
<div className="flex space-x-4">
<Link to="/" className="hover:underline text-white">
Home
</Link>
<Link to="/events" className="hover:underline text-white">
Events
</Link>
<Link to="/gallery" className="hover:underline text-white">
Gallery
</Link>
<Link to="/upload" className="hover:underline text-white">
Upload
</Link>
<Link to="/login" className="hover:underline text-white">
Login
</Link>
</div>
</nav>
);
};
export default Navbar;
λ‘κ·ΈμΈ νμ΄μ§
const Login = () => {
return (
<div className="p-6 text-center">
<h2 className="text-3xl font-bold">Sign In</h2>
<p className="text-gray-600 mt-2 pb-16">λ‘κ·ΈμΈνμΈμΌ</p>
<div className="flex justify-between items-center pb-16 h-[100px] w-[360px]">
<span className="flex flex-col gap-4 items-start h-[100px]">
<label className="h-[42px] flex items-center" htmlFor="signin-id">
ID
</label>
<label className="h-[42px] flex items-center" htmlFor="signin-pwd">
PASSWORD
</label>
</span>
<span className="flex flex-col gap-4 items-center h-[100px]">
<input
className="border p-2 w-[250px] rounded-md"
type="text"
id="signin-id"
name="signin-id"
/>
<input
className="border p-2 w-[250px] rounded-md"
type="password"
id="signin-pwd"
name="signin-pwd"
/>
</span>
</div>
<button className="bg-blue-600 text-white py-2 px-4 rounded-md hover:bg-blue-700 w-[360px]">
Sign In
</button>
</div>
);
};
export default Login;
κ²°κ³Ό
μΌλ¨μ ꡬν~λ°°ν¬λΆν° ν΄λκ³ λμμΈ κ°μ μ λμ€μ μκ° λ¨μΌλ©΄ νλ κ±Έλ‘!