import { useRoutes } from 'react-router-dom';
const App = () => {
const routes = useRoutes([
{ path: '/', element: <TimerPage /> },
{ path: '/clock', element: <ClockPage /> },
{ path: '/stopwatch', element: <StopWatchPage /> },
{ path: '/alarm', element: <AlarmPage /> },
]);
return (
<>
<Header />
<ContentContainer>
<NavBar />
{routes}
</ContentContainer>
</>
);
};
와 같은 식으로 사용할 수 있다.
path설정같은거 할때 쉽게 정리 가능해서 나름 유용한 것 같다.
v6.0 이전에는 react-router-config 였다고 한다.
일반적 Routes와 쓰이는것도 똑같고 무엇을 쓸지는 취향차이라고 합니다..
React Router says, "Honestly, we like and use them both."
라고 공식문서에 돼 있다고 합니다.
'프로그래밍 공부내용 > 리액트(React)' 카테고리의 다른 글
Batching에 관하여(리액트 setState 비동기 묶지 않고 따로따로 처리 하기) (0) | 2022.06.05 |
---|---|
1. Introduction - MSW (Mocking Service Worker) 공식문서 따라 읽기 및 사용설명 (0) | 2022.05.17 |
라우터 기본 사용법과 link와 navLink의 차이 (0) | 2022.05.09 |
리액트와 순수함수 (0) | 2022.05.05 |
Create portal (0) | 2022.05.04 |