일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- UnrealEngine
- 개발
- character
- 개발블로그
- 오블완
- ANIMATION
- ue5
- iclone
- 프로그래밍
- visualstudio
- modeling
- animating
- 애니메이팅
- js
- charactercreator
- C언어
- 3dmodeling
- 티스토리챌린지
- HTML
- C
- cc4
- autodesk
- c++
- 마야
- Costume
- unreal
- 언리얼엔진
- reallusion
- JavaScript
- 3d
Archives
- Today
- Total
개발나라 스용공주
[React] 라우트(Route) 설정하기 본문
728x90
728x90
import { Routes, Route } from 'react-router-dom'
// /입력 시 Home, /new new, /diary diary 각각의 페이지를 가져오도록 하기 위함
Routes와 Route를 사용하면 원하는 경로로 원하는 컴포넌트를 연결해줄 수 있다.
return (
<Routes>
<Route path="/" element={<Home/>}/>
<Route path="/new" element={<New/>}/>
<Route path="/diary" element={<Diary/>}/>
<Route path="*" />
</Routes>
// path는 경로 element는 해당 경로에서 렌더링할 컴포넌트 작성
// Routes는 위에서부터 순서대로 순회
// ex. /new라는 path를 찾았다면 해당 <New> 컴포넌트에 해당하는 페이지를 렌더링
// path가 *일 경우 위의 조건들이 모두 없을 경우 띄우는 페이지 (default)
)
}
import "./App.css";
import { Routes, Route } from "react-router-dom";
import Diary from "./pages/Diary";
import Home from "./pages/Home";
import New from "./pages/New";
import Notfound from "./pages/NotFound";
function App() {
return (
<Routes>
<Route path="/" element={<Home />} />
<Route path="/new" element={<New />} />
<Route path="/diary" element={<Diary />} />
<Route path="*" />
</Routes>
);
}
export default App;
주의사항 1) Routes 컴포넌트 안에는 Route 컴포넌트만 들어갈 수 있다.
주의사항 2) Routes 컴포넌트 밖에 작성된 것은 모든 페이지에 렌더링된다.
728x90
728x90
'WEB > React' 카테고리의 다른 글
[React] 동적경로 - useParams, useSearchParams (0) | 2025.04.19 |
---|---|
[React] 페이지 이동하기 - Link, useNavigate (0) | 2025.04.19 |
[React] 이벤트를 활용하여 키보드 인식하기 (0) | 2025.04.19 |
[React] useReducer - state를 생성하는 리액트 훅(React Hook) (0) | 2025.04.18 |
[React] 동적 경로의 종류와 사용법 - URL Parameter와 Query String (0) | 2025.04.10 |
Comments