The history object is available to the component rendered with a <Route> match. In the preceding example, the DashboardComponent was rendered as a result of navigation to the path /dashboard. The rendered component received the props, which contained the history object (as well as match, location, and staticContext). In a case where, the rendered component on the page is not the outcome of a route navigation, the history object will not be available to the component.
Consider a FooterComponent included in App.js :
class FooterComponent extends Component {
render() {
return (
<footer>
In Footer
<div>
<button
onClick={() =>
this.props.history.push('/user')}>
...