본문 바로가기
개발/에러해결

export 'Switch' (imported as 'Switch') was not found in 'react-router-dom'

by amkorousagi 2022. 10. 22.

에러 내용


export 'Switch' (imported as 'Switch') was not found in 'react-router-dom'

export 'Switch' (imported as 'Switch') was not found in 'react-router-dom' ...

에러 원인


reactrouter가 업그레이드되면서 더 이상 Switch를 지원하지 않는다.

 

해결 방법


 

Switch 대신 Routes를 사용한다.

 

수정 전 코드 : Switch 사용

<BrowserRouter>
  <Switch>
    <Route path="/" element={<Home />} />
  </Switch>
</BrowserRouter>

 

수정 후 코드 : Routes 사용

<BrowserRouter>
  <Routes>
    <Route path="/" element={<Home />} />
  </Routes>
</BrowserRouter>

 

결과

result

참고 자료


 

 

Upgrading from v5

Upgrading from v5 Backwards Compatibility Package We are actively working on a backwards compatibility layer that implements the v5 API on top of the v6 implementation. This will make upgrading as smooth as possible. You'll be able to upgrade to v6 with mi

reactrouter.com

 

댓글