'Event Listener on Navigation with react router v6
I would like to add an event listener to a navigate event in react router v6. I have not found anything to it. Is there such a feature?
Edit: When the event is handled, I want to prevent the navigation and route the user to another destination, which depends on where he is comming from.
Solution 1:[1]
You can useLocation() and useEffect().
const location = useLocation();
useEffect(() => {
console.log("url changed")
}, [location]);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jax-p |
