I am building a website in react with multiple pages using react-router-dom and I want to be able to handle the equivalent of a window 'beforeunload' event whenever I am about to switch pages using react-router. I am pretty new to react, so maybe there is an obvious solution I'm not seeing?
I have tried useEffect with history.block as shown here, and just adding a window 'beforeunload' event, but this only seems to work for reloading, closing, or leaving the domain, not for clicking internal links or back/forward navigation.