Defining Routes

Developed with

The course is part of this learning path

ReactJS: Zero to Hero
Start course


This module looks at how to Route in React. You’ll be looking at linking components, creating dynamic links, parameterized routes, and how to install the React Router DOM.

Learning Objectives 

The objectives of this module are to provide you with an understanding of: 

  • How to install the React Router DOM 
  • Hooks in React  
  • How to create restful services  
  • How to use an Effect Dependency Array  
  • How to hand errors in data requests  
  • How to send data   

Intended Audience  

This learning path is aimed at all who wish to learn how to use the ReactJS framework.  


It is essential you understand the face of contemporary web development to attend this course. You should also have JavaScript experience, along with good HTML and CSS skills.


We welcome all feedback and suggestions - please contact us at to let us know what you think. 


For our app component, we've now added three Route components. The one on line 24 defines the Route for the path for the search link. We use the exact attribute here, so that this path only matches when there are no other segments in the URL. This Route renders the FilterableCoursesTable component when the path and the location path name match. The Route on line 24 has a path of /add, and this will render the AddCourseForm component when the location path name is /add. The Route on line 35 has no path property. This will render if no other Route matches. Inside this, we use React Router DOM's Redirect component. Used like this, it simply forwards the location to the value specified in the to attribute. In this case, to /. You can read more about this component and it's options in the React Router DOM documentation. You can see that we have surrounded the Route components in a Switch component. The Switch component is very useful as it ensures that React renders the first Route or Redirect that matches the location. If we didn't have the Switch component around our Routes, any Route that matched would render. Again, you can read more about the Switch component in the documentation. Clicking on each of the Route displays the views as specified. Clicking Add and Search display as we would want. The Unmatchable Route link, as you can see in the code, tries to go to a location that we don't have a Route for. In this case, the Redirect is activated, and the user is taken to the /Route and the FilterableCoursesTable is rendered. So, now we are able to render different views in the app without having to make requests for new pages, but there is more we can do with routing like rendering views with particular data in them depending on what the user has clicked.

About the Author
Learning paths6

An outstanding trainer in software development with more than 15 years experience as a Corporate and Apprentice Trainer, ICT Teacher and Head of Department, with a passion for technology and its uses. Continuing to develop existing and new skills and courses, primarily in web design using PHP, JavaScript, HTML, CSS and SQL but also OOP (Java), programming foundations (Using Python), DevOps (Git, CI/CD, etc) and Agile/Scrum. Practically minded, a quick learner and a problem solver with an attention to detail to ensure high quality outcomes.

Covered Topics