useLocation
declare function useLocation(): Location;
interface Location extends Path {
state: any;
key: Key;
}
This hook returns the current location
object. This can be useful if you'd like to perform some side effect whenever the current location changes.
import * as React from 'react';
import { useLocation } from 'react-router-dom';
function App() {
let location = useLocation();
React.useEffect(() => {
// Google Analytics
ga('send', 'pageview');
}, [location]);
return (
// ...
);
}