Is there any lifecycle hook like window.onbeforeunload in Angular2? I already googled and searched on stackoverflow, but found nothing
This worked for me. Defined in the page component constructor
window.addEventListener("beforeunload", (event) => {
event.preventDefault();
event.returnValue = "Unsaved modifications";
return event;
});
Define the returnValue only if you want to prompt user before unload.
Work only if the user interract with the page (e.g. click).