Can you process additional logic when leaving the page?

I have a page that is used for modifying settings for the user on my application. The application requires a manual save which some users may forget to do when moving to another page via the side-menu or going back with the hardware back-button.

Is it possible to process additional logic when a user tries to change their “url” to go to another state or page? For example in this event if a value on a form has been changed I would like to show a pop-up asking the user if they would like to save the changes or not before proceeding to the next page.

Thanks for any help.

Please have a look at this ink

//do something here

and there is beforeLeave also.