Call function when navigating to previous view

Hey, i have a app with the user edit form, and i want it to save the changes to the database whenever the user leaves the user edit route.

I have thought of using $stateChangeSuccess on the previous state, but i don’t think it will be ‘performance friendly’.

Is there any method to detect the ‘next state’ and call a function when im about to transition to a specific one?

Thanks in advance,

Bruno Duarte Brito