Defining Routes

Learn how to define routes based on path/URL matching using the Route component.

Route component

Each component placed inside the <Router></Router> element can access the router context, react to it, or manage it. We create routes by using the Route component and providing a path prop and an optional render or component prop (the exception being the 404HTML error message for page not found or file not found route). The value of a render prop must be a function that returns a valid React element. The component prop expects a component, not an element.

The correct implementation of both props can be summarized as follows:

Get hands-on with 1400+ tech skills courses.