Skip to content

Suggestion about Switch on app.js and the react-router-dom dependency #6

@chavez-carlos

Description

@chavez-carlos

In the video, you utilized:

<Switch>
        <Route path='/' exact component={Home} />
        <Route path='/about' component={About} />
        <Route path='/services' component={Services} />
        <Route path='/contact-us' component={Contact} />
        <Route path='/sign-up' component={SignUp} />
      </Switch>

But I got some errors when compiling it: Attempted import error: 'Switch' is not exported from 'react-router-dom'

After investigating a little bit, I found that since v6 of react-router-dom, Switch is replaced by Routes, making this change on my project solved the issue:

import { BrowserRouter as Router, Routes, Route } from 'react-router-dom';
...
<Routes>
        <Route path='/' element={<Home/>} />
        <Route path='/about' element={<About/>} />
      </Routes>

I think it would be nice if you pinned a comment on the video or to update it.
Thanks for the tutorial.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions