dev
Branches
main (6.4.1)dev
Versions
6.4.1v4/5.xv3.x
useLocation

useLocation

Type declaration
declare function useLocation(): Location;

interface Location extends Path {
  state: unknown;
  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(() => {
    ga('send', 'pageview');
  }, [location]);

  return (
    // ...
  );
}
Docs and examples CC 4.0
Edit