[React] You should not use <Route> outside a <Router>

uoayopยท2021๋…„ 5์›” 27์ผ
0

์—๋Ÿฌ ํ•œ๋ฐ”๊ฐ€์ง€

๋ชฉ๋ก ๋ณด๊ธฐ
9/16
post-thumbnail

์ƒํ™ฉ
react-route-dom์„ ์„ค์น˜ํ•˜๊ณ  App.js์— ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜๋‹ˆ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ–ˆ๋‹ค.

<Route path="/today" component={Today}/>
<Route path="/new" component={New}/>
<Route path="/hot" component={Hot}/>
<Route path="/product" component={Product}/>

์—๋Ÿฌ ์ฝ”๋“œ

Error: Invariant failed: You should not use <Route> outside a <Router>

ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•
1.github issue / Error: Invariant failed: You should not use <Route> outside a <Router>

2.Error: Invariant failed: You should not use <Route> outside a <Router>

index.js์— ์œ„์น˜ํ•œ <App />์„ <BrowserRouter> ๋กœ ๋ฌถ์–ด์ฃผ๋ฉด ๋œ๋‹ค!

ReactDOM.render(
  <React.StrictMode>
    <BrowserRouter>
      <App />
    </BrowserRouter>
  </React.StrictMode>,
  document.getElementById('root')
);

BrowserRouter๊ฐ€ ๋ญ”์ง€ ๊ณต๋ถ€ํ•˜๊ณ  ์ •๋ฆฌํ•ด๋ด์•ผ๊ฒ ๋‹ค.

profile
slow and steady wins the race ๐Ÿข

0๊ฐœ์˜ ๋Œ“๊ธ€