react history listen get previous location

JavaScript
let prevLocation;

history.listen(nextLocation => {
  console.log(prevLocation);
  // ...
  prevLocation = nextLocation;
});
Source

Also in JavaScript: