Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

Ryli Davis
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Ryli Davis
Full Stack JavaScript Techdegree Graduate 14,439 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 {
  BrowserRouter, 
  Routes,
  Route
} from 'react-router-dom';

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


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


export default App;