- 처음 작성 했던것
import { Routes, Route } from "react-router-dom";
import Video from "./components/Video/Video";
import VideoDetail from "./components/Video/VideoDetail";
import NotFoundPage from "./pages/NotFoundPage";
function App() {
return (
<>
<Routes>
{}
<Route path="/videos" element ={<Video/>}>
<Route path=":id" element ={<Video/>}/>
</Route>
{}
<Route path="/videos/watch" element ={<VideoDetail/>}>
<Route path=":id" element ={<VideoDetail/>}/>
</Route>
{}
<Route path="*" element={<NotFoundPage/>} />
</Routes>
</>
);
}
export default App;
- 더 나은 버전
import { Routes, Route } from "react-router-dom";
import Video from "./components/Video/Video";
import VideoDetail from "./components/Video/VideoDetail";
import NotFoundPage from "./pages/NotFoundPage";
import Card from "./components/UI/Card";
function App() {
return (
<>
<Routes>
<Route path="/" element={<Card />}>
<Route path="videos" element ={<Video/>}/>
<Route path="videos/:id" element ={<VideoDetail/>}/>
<Route path="videos/watch" element={<VideoDetail />} />
<Route path="videos/watch/:id" element={<VideoDetail />} />
</Route>
<Route path="*" element ={NotFoundPage}/>
</Routes>
</>
);
}
export default App;
- Card 컴포넌트
import React from "react";
import classes from "./Card.module.css";
import { Outlet } from "react-router-dom";
import Header from "../Header/Header";
function Card() {
return (
<div className={classes.Card_Container}>
<Header />
<Outlet />
</div>
);
}
export default Card;