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 4 years ago
Updated 3 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.

egghead
egghead
~ 15 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today