Detect URL Route change in ReactJS


To detect a URL change in a single page React application you can use the following code snippet:

 

import { withRouter } from 'react-router-dom';

history.listen((location, action) => {
console.log("on route change");
// Do stuff.
})