Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- Firebase
- router
- onAuthStateChanged
- 자바스크립트
- lv.0
- 뒤집기
- 9쪽이들
- 심화프로젝트
- 최종프로젝트
- 상태변화감지
- LAN 과 WAN
- 배열
- redux
- 프로세스
- S.A
- 에러
- 닉네임보이게하기
- react-router-dom
- typescript
- CS
- Toolkit
- DoM
- react
- 계층
- 쓰레드
- #kakaomap
- react-full-page
- 비선형 자료구조
- useref
- 프로그래머스
Archives
- Today
- Total
행복한 딸기 🍓
react-router-dom : 페이지 이동 본문
패키지 설치 (yarn)
yarn add react-router-dom
페이지 생성
페이지 넘어가는 경로? 만들기
// Router.js
import { BrowserRouter, Route, Routes } from "react-router-dom";
import Home from "../pages/Home";
import About from "../pages/About";
import Contact from "../pages/Contact";
import Works from "../pages/Works";
const Router = () => {
return (
<BrowserRouter>
<Routes>
<Route path="/" element={<Home />} />
<Route path="/about" element={<About />} />
<Route path="/contact" element={<Contact />} />
<Route path="/works" element={<Works />} />
</Routes>
</BrowserRouter>
);
};
export default Router;
App.jsx에서 Router를 가져온다.
// App.jsx
import "./App.css";
import Router from "./shared/Router";
function App() {
return <Router />;
}
export default App;
주소 검색 이동
...localhost:3000/ ➡️ Home.jsx
...localhost:3000/about ➡️ About.jsx
...localhost:3000/contact ➡️ Contact.jsx
...localhost:3000/works ➡️ Worsk.jsx
'TIL' 카테고리의 다른 글
[react-router-dom] useLocation : 현재 위치를 알려준다. (0) | 2023.07.11 |
---|---|
Styled Components (0) | 2023.07.10 |
⭐DOM & Virtual DOM (0) | 2023.07.05 |
json-server: command not found (0) | 2023.07.04 |
[React] useMemo : value memoization (0) | 2023.07.03 |