React ~ Router ~ Events - rohit120582sharma/Documentation GitHub Wiki

When a <Route> matches, it passes the location, match, and history objects to the rendered component as props.

We can add listener to history object for route change events.

import React, { Component } from 'react';
import { withRouter } from 'react-router-dom';

class App extends Component {
  constructor(props) {
    super(props);
    
    // Here we go
    this.props.history.listen((location, action) => {
      console.log("on route change");
    });
  }

  render() {
    return (
      <h1>App Component...</h1>
    );
  }
}
export default withRouter(App);

⚠️ **GitHub.com Fallback** ⚠️