React
[์ค๋ฅ ํด๊ฒฐ] 'Switch' is not exported from 'react-router-dom'
๋ฌด๋ธ๋ก๋
2022. 1. 30. 14:40
728x90
๐ ์์ธ
react-router-dom์ด v6๋ก ์ ๋ฐ์ดํธ ๋์๊ธฐ ๋๋ฌธ์ด๋ค.
v6์์๋ Switch๊ฐ ์๋ ๋ค๋ฅธ ๋ฐฉ๋ฒ์ ์ฌ์ฉํ๋ค.
๐ ๊ทธ๋์ ํด๊ฒฐ ๋ฐฉ๋ฒ์?
// v5 <Router> <Switch> <Route exact path="/" component={Home} /> <Route exact path="/Board" component={Board} /> </Switch> </Router> // v6 <Router> <Routes> <Route path="/" element={<Home />} /> <Route path="/Board/*" element={<Board />} /> </Routes> </Router>
์์ ๊ฐ์ด v6์์๋ Switch๊ฐ ์๋ Routes๋ฅผ ์ฌ์ฉํ๋ฉฐ,
exact๋ ์ฐ์ง์๊ณ , component๊ฐ ์๋ element๋ฅผ ์ด์ฉํ๋ค.
๋ง์ฝ ์์๋ก ์ฌ๋ฌ ๋ผ์ฐํ ์ ๋งค์นญํ๊ณ ์ถ์ ๋ *๋ฅผ ์ด์ฉํฉ๋๋ค.
๐ ์ฑ๋ฅ
70% ์์์ง ๋ฒ๋ค ์ฌ์ด์ฆ๋ก ์ธํด ์ฑ๋ฅ์ด ์ํฅ ๋์์ต๋๋ค.
์ถ์ฒ : https://miracleground.tistory.com/entry/Error-Switch-is-not-exported-from-react-router-dom-%ED%95%B4%EA%B2%B0