๐ย ์ค์นํ๊ธฐ
https://reactrouter.com/docs/en/v6/getting-started/overview
$ npm i react-router-dom@5.3.0
$ yarn add react-router-dom
import { BrowserRouter, Route, Link, Routes} from "react-router-dom";
<Router>
<Routes>
<Route path="/" >
<Home />
<Route/>
<Route path="/about">
<About />
<Route/>
</Routes>
</Router>
path ์์ url์ด ์๋ค๋ฉด, Home์ปดํฌ๋ํธ๋ฅผ ๋ณด์ฌ์ค๋ค.
Switch ๋ง๊ณ Routes๋ฅผ ์ฐ๋๋ก ํ์
import { BrowserRouter, Route, Link, Routes } from 'react-router-dom';
function App() {
return (
<BrowserRouter>
<div>
<Link to="/">Home</Link>
<br />
<Link to="/movie">Movie</Link>
<br />
<Link to="/about">About</Link>
<br />
</div>
<Routes>
<Route exact path="/" element={Home} />
<Route path="/movie" element={Movie} />
<Route path="/about" element={About} />
</Routes>
</BrowserRouter>
);
}
ํ Route ์์ ๋ค๋ฅธ Route๋ก ์ด๋ํ๋ ๋ฐฉ๋ฒ์??
<h1>
<Link to="/movie">{title}</Link>
</h1>
์ด๋ ๊ฒ Link์ปดํฌ๋ํธ๋ฅผ import ํ ๋ค์, url์ ์ถ๊ฐํ๋ฉด ๋๋ค