Detect ionic Nav Back Button pressed on specific page

I have several form pages and want to be able to detect when the user presses the ionic nav back button to warn them they are navigating away from the form and ask if they are sure they want to leave.

Is there a way to listen for this event in the view controller or attach an onclick event somehow?



i would focus on the stateChange and not so much the button click.

   function (event, toState, toParams, fromState, fromParams) {

Thanks, I am just not sure how to implement it using stateChange though. I know I cant be the only one who has wanted to do this?