J
J
JS Noob2020-01-30 23:06:31
React
JS Noob, 2020-01-30 23:06:31

What if you don't use the Switch component from the react-router package?

If you do not use the Switch wrapper, the routes work fine, why is it needed then?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
XaveScor, 2020-01-31
@JS_Noob

needed to render only the first matching route from the list. If not, then all routes that match the passed conditions will be rendered.

<Switch>
  <Route path="/" component={A} /> // <-- будет отрендерен только этот роут
  <Route path="/" component={A} />
</Switch>

<>
  <Route path="/" component={A} /> // <-- будет отрендерен этот роут
  <Route path="/" component={A} /> // <-- и этот так же будет отрендерен
</>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question