All I could find concerning listening to the location change is a code like:
const location = useLocation();
useEffect(() => {}, [location]);
But the issue I'm trying to solve is to understand whether the user went back or forward on the page, which the location object doesn't provide by itself.
My business requirement is to log out the user when they press "back" and the "back" page was a log in page which successfully logged the user in. I solved flagging the location via location.state
to understand whether it's a post-successful-login route. Now I want to listen to the "back" action in the browser and emit the logout
flow based on location.state
.
If you have a better solution I'm all ears.