Using "beforeunload" with live redirects

Thanks for the reply, yes I tried this approach already something like this

On mount, I could do

      const links = document.querySelectorAll("a")
      for (var i = 0, len = links.length; i < len; i++) {
        links[i].addEventListener("click", triggerBeforeUnload);
      }

This works but I believe it is not the best idea, for example the live view might add new links to the dom on a certain user interaction which would not have the event listener and would therefore fail to intercept the event.

I feel like this is a common use case and there should be a elegant way to handle it.