...

/

Connecting Components with a Router Using Higher-order Component

Connecting Components with a Router Using Higher-order Component

Learn how to receive the Router's props using a higher-order component and pass the props to the wrapped component whenever it renders.

We'll cover the following...

a Each component used as a component prop in a Router element is automatically passed the router props history, location, and match. Sometimes, however, it’s useful to be able to access Router functionality in components that are not using a direct route—for example, to redirect to another page using history.push().

The withRouter higher-order component

React Router provides a withRouter higher-order ...