Print every URL visited in the console

269 Views Asked by At

I'm taking over a web application written by someone else in React+Node+Express+Redux+Umi. I'm new to React+Redux+UMI.

It is not a web site that we could see Url in a web browser. But I can use Chrome Dev Tools for debugging. I want to insert some code to the frontend, so that each time the URL (before redirection and after redirection) of the visited pages is printed in the console. Does anyone know where I could insert the code to this React application?

1

There are 1 best solutions below

0
On BEST ANSWER

In your top level app component you can use one of react-routers hooks to do this.


function App() {

  const location = useLocation();

  useEffect(() => {
      console.log(`route change: ${location.pathname}`);
  }, [location.pathname]);

}