I have an application where the user enters a good deal of information. Accordingly, it is important to use the beforeunload
event so that the user doesn't accidentally leave the page and lose their progress. However, the app also requires download links and the problem is that clicking those download links triggers the beforeunload event even though the download does not cause the user to leave the page.
How can I set this up so that the the user has to confirm before leaving the page but that this confirmation is not triggered by clicking a download link?
You can see the whole thing in a reproducible example here:
Live page: https://wqy9kn5qv7.codesandbox.io/
Source code: https://codesandbox.io/s/wqy9kn5qv7