์ƒˆ์†Œ์‹

React

[์˜ค๋ฅ˜ ํ•ด๊ฒฐ] 'Switch' is not exported from 'react-router-dom'

  • -
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

'React' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

๐Ÿš€ [React + Node.js(Express)] ์—ฐ๋™ํ•ด๋ณด์ž  (0) 2022.01.30
Contents

ํฌ์ŠคํŒ… ์ฃผ์†Œ๋ฅผ ๋ณต์‚ฌํ–ˆ์Šต๋‹ˆ๋‹ค

์ด ๊ธ€์ด ๋„์›€์ด ๋˜์—ˆ๋‹ค๋ฉด ๊ณต๊ฐ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค.