Add routes to a react app using reach Router

Khaled Garbaya
InstructorKhaled Garbaya
Share this video with your friends

Social Share Links

Send Tweet
Published 5 years ago
Updated 4 years ago

Khaled Garbaya: [0:00] Let's go back to our terminal. Let's stop our server and open this project in our editor. Let's open App.js. Let's delete all of this code.

[0:13] We need to install Reach Router. We do yarn add @reach/router. Once that's done, let's import the link and create couple of links. First link will be to the path timeline. We will add two more links, one for policy and one for about. Let's wrap this in a nav.

[0:52] After we define the links, let's define some routes. Here we'll have our Router. First one will be Timeline with the path timeline. Second one will be Policy. Third one will be About.

[1:25] Let's define these components. First Timeline, this we'll return <h1>, same Timeline for now. We need two more components. One is Policy and this is same, Policy. This one will be About.

[1:49] Let's do yarn. Start. Here I have a typo. It's Policy. You can see here I have my links, TimelinePolicyAbout.

[2:08] We need to fix the path About also and here, we can add some space in between. Let's go back, see here About, Policy.