Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
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
Archives
Today
Total
관리 메뉴

ENN

[React] 리액트 Router 본문

프론트엔드

[React] 리액트 Router

k.dahee 2022. 9. 11. 11:25

1. react-router

- 해당되는 URL에 따라 페이지를 이동하는 것을 Routing이라고 함. 

- React-Router는 리액트의 네비게이션 라이브러리로 사용됨.

 

react-router-dom라이브러리

1) Link

- to ="URL"을 통해서 이동경로를 지정해줌.

<Link to ="/home"> Home</Link>

2) Router

- Route와 Link컴포넌트를 유기적으로 묶어주며,  route와 link 컴포넌트는 항상 router를 상위 컴포넌트로 가져야함

<Router>
	<Link />
    <Link />
    <Router />
    
</Router>

실제로 라우팅 구현

<Router>
            
            <Routes>
                <Route path="/" element={<Home />} exact />
                <Route path="/signin" element={<SigninPage />} exact />
                <Route path="/signup" element={<SignUpPage />} exact />
                <Route path="/MyInfo" element={<MyPage />} exact />
                <Route path="/forgotIdPw" element={<FindIdPw />} exact />
            </Routes>
</Router>

- <Routes>컴포넌트는 여러개의 Route를 감싸고, 그 중 규칙이 일치하는 Route를 렌더링 시켜줌.

 

-<Route>는 path="", element 에는 컴포넌트를 넣어줌.

'프론트엔드' 카테고리의 다른 글

Styled-components  (0) 2022.09.14
Next.js  (0) 2022.09.14
Redux, react-redux, redux toolkit  (0) 2022.09.13
리액트 훅(useState, useEffect, useMemo, useCallback, useRef,  (0) 2022.09.13
npx vs npm vs yarn  (0) 2022.09.10