route
-
React - Router 화면 이동WEB/React 2022. 4. 30. 02:23
화면을 이동하기 위해서는 npm i react-router-dom npm i @types/react-router-dom 위 두 개를 설치해 준다. index.tsx 파일에 를 추가해 준다. ReactDOM.createRoot(document.getElementById('root')!).render( ) 그 후 원하는 App.tsx에 라우터를 추가해 준다. const routes = [ {path: "/Test",component : }, {path: "/sample",component : }, ] return( {routes.map((route : {component : JSX.Element, path : string}, index : number) => ( ))} ) 위와 같이 작성한다면 routes에..