So I have a SPA application built in angular, now my issue is when a user is on my app if they press the (browser) back button, sometimes if data was sent on the previous page it can cause errors and sometime there is state that when refreshed goes away. Now Is there a way I can warn a user before going back or simply not allow a user to go back??
I have tried to do this in my index.html
<script>
window.onbeforeunload = function() {
return "Message";
};
</script>
but it looks like this no longer works on newer browsers, I found a similar question here but its from a few years ago and I've tried a few of there solutions and none of them worked..
what is the best way in 2018 to handle this situation??
Thanks