Trying to notify the user about any unsaved modifications in my Vue component's
beforeRouteLeave (to, from, next)
route hook. I want to showcase this prompt on navigation or reload:
https://i.sstatic.net/Qga1Z.png https://i.sstatic.net/fONR8.png
My approach involves utilizing the window.onbeforeunload
event, however, it's not working as expected:
beforeRouteLeave (to, from, next) {
if (!this.changesSaved) {
const response = window.onbeforeunload = function(e) {
return 'Are you sure you want to leave? There are unsaved changes!';
};
if (response) {
return next()
} else {
return next(false)
}
}
return next()
}
What am I missing here in terms of syntax?