Switch' is not exported from 'react-router-dom

sonyrainy·2023년 4월 19일

ERROR

목록 보기
2/2

😾 ERROR

node.js를 배우고 있는데, npm run start를 terminal에 입력했는데, ERROR가 떴다.

Switch' is not exported from 'react-router-dom

😸 해결방법

v5에서 v6으로 넘어오면서,

1) Switch가 Routers로 변경되었다.
2) exact는 더 이상 사용되지 않는다.
3) component가 element로 변경되었다.

// v5 버전
<Switch>
 <Route exact path="/" component={Home} />
 <Route path="/report" component={Report} />
 <Route path="/passenger" component={Passenger} />
</Switch>

// v6 버전
<Routes>
 <Route path="/" element={<Home />} />
 <Route path="/report" element={<Report />} />
 <Route path="/passenger" element={<Passenger />} />
</Routes>

즉, 코드를 수정하거나 버전을 다운그레이드하여 사용할 수 있다.

npm uninstall react-router-dom
npm install react-router-dom@5.2.0

yarn remove react-router-dom
yarn add react-router-dom@5.2.0

+) 아직 v5를 사용해도 괜찮을까?
ㅇㅇ


출처 : https://miracleground.tistory.com/entry/Error-Switch-is-not-exported-from-react-router-dom-%ED%95%B4%EA%B2%B0

profile
@sonyrainy

0개의 댓글