How to call an api on every path/route change?

Viewed 37

I wish to call an API on the path/route change of a react web app. How can I achieve this if I wish to call an API only once the route or the path changes.

Note that I have tried this in route file inside an useEffect by giving dependency of the route but it is executing for all the routes at once, eg. 50 routes, 50 API calls which is expected.

Is there anything with which help I can achieve this?

0 Answers
Related