Routing with React Router 4
This example application is using React Router 4, which allows you to visit different rendered components based on the URL. This chapter will briefly go over the basics of React Router 4. However, it’s strongly recommended to check out their documentation.
React Router 4 Documentation: https://reacttraining.com/react-router/.
First, you’ll want to install React Router 4 with the following command:
npm install react-router-dom --save
Next, import two specific components of react-router-dom
and those are BrowserRouter
and Route
. You can do that with an ES6 import statement in your App.js
file.
import { BrowserRouter, Route } from 'react-router-dom';
Next, import your components that you will create. You can actually import these later once you create them. If you import them before, you’ll get an error. Just be sure to reference this section later when you’re ready to tie routes to components.
BrowserRouter
<BrowserRouter...