# From Switch to Routes (React)

**URL:** <https://forum.freecodecamp.org/t/from-switch-to-routes-react/494142>\
**Category:** Curriculum Help\
**Tags:** javascript\
**Created:** [January 25, 2022, 6:58pm UTC](https://forum.freecodecamp.org/t/from-switch-to-routes-react/494142 "2022-01-25T18:58:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![7ing7ing](https://avatars.discourse-cdn.com/v4/letter/7/73ab20/32.png) [@7ing7ing](https://forum.freecodecamp.org/u/7ing7ing)\
**Post date:** [January 25, 2022, 6:58pm UTC](https://forum.freecodecamp.org/t/from-switch-to-routes-react/494142/1 "2022-01-25T18:58:36Z")

</div>

Hey there.

I’m using React to make an app and just found that the Switch component has been updated to Routes component. I had a look at the documentation in order to update my code.

So, my code was like this:

```auto

function App() {
  return (
    <Router>
    <div className="app">
      <Switch>
        <Route path="/">
          <Header/> 
          <Home/>
        </Route>
      </Switch>
    </div>
    </Router>
  );
}

```

Naturally, it did not work as apparently I have react router v6.

I did change my code to this:

```auto
function App() {
  return (
    <Router>
    <div className="app">
      <Routes>
        <Route path="/" element={[<Header/>, <Home/>]}>
        </Route>
      </Routes>
    </div>
    </Router>
  );
}

```

My concern is the following:

In the first option (Switch) you can type anything after the slash, and it works. Example: [http://localhost:3000/qwerty](http://localhost:3000/qwerty)

But, when I type the same thing when usng Routes, it does not work.

What am I missing?

---

<div class="post-metadata">

**Author:** ![jenovs](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jenovs/32/60963_2.png) [@jenovs](https://forum.freecodecamp.org/u/jenovs)\
**Post date:** [January 25, 2022, 7:12pm UTC](https://forum.freecodecamp.org/t/from-switch-to-routes-react/494142/2 "2022-01-25T19:12:15Z")

</div>

In RRv6 all routes by default are `exact`.  
Try adding another route with `path="*"` (or replace “/” with “\*” in your route).

---

<div class="post-metadata">

**Author:** ![7ing7ing](https://avatars.discourse-cdn.com/v4/letter/7/73ab20/32.png) [@7ing7ing](https://forum.freecodecamp.org/u/7ing7ing)\
**Post date:** [January 25, 2022, 7:18pm UTC](https://forum.freecodecamp.org/t/from-switch-to-routes-react/494142/3 "2022-01-25T19:18:11Z")

</div>

Thank you so much. I missed that they were exact.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/freecodecamp/original/3X/e/1/e1c433102e34b46dfaa3e15d13ab9a514b127078.svg) [@system](https://forum.freecodecamp.org/u/system)\
**Post date:** [July 27, 2022, 7:19am UTC](https://forum.freecodecamp.org/t/from-switch-to-routes-react/494142/4 "2022-07-27T07:19:00Z")

</div>

Closed on July 27, 2022, 7:19am UTC

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.
