Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript React Router 4 Basics Getting Started with React Router Installing React Router and Declaring Routes

Ryli Davis
.a{fill-rule:evenodd;}techdegree seal-36
Ryli Davis
Full Stack JavaScript Techdegree Graduate 15,136 Points

UPDATED react-router-dom v6 - Need to also import Routes. Need to add <Routes> outside of <Route path> and etc:

This video is outdated and doesn't follow the newest react-router-dom v6 guidelines. I was getting the error of:

Error: A <Route> is only ever to be used as the child of <Routes> element, never rendered >directly. Please wrap your <Route> in a <Routes>.

I found out that 'component' is replaced with 'element'. We also need to add 'Routes' to be imported as well from React-Router-Dom, and we need to wrap <Routes> </Routes> around the <Route path> statement. The following code worked for me:

import React from 'react';
import {
} from 'react-router-dom';

// App components
import Home from './Home'

const App = () => (
  <div className="container">
<Route path="/" element={<Home /> } />

export default App;