The other examples here work fine for the old versions of ui-router (>=0.3.x) but all state events, such as $stateChangeStart
, are deprecated as of 1.0. The new ui-router 1.0 code uses the $transitions service. So you need to inject $transitions
into your component then use the $transitions.onBefore method as the code below demonstrates.
$transitions.onBefore({}, function(transition) { return confirm("Are you sure you want to leave this page?"); });
This is just a super simple example. The $transitions
service can accept more complicated responses such as promises. See the HookResult type for more information.