angular-ui/ui-router — pull request #591 by 2ix (2013-11-20 23:38:57+00:00)
Title: Expose `$urlRouterUpdateStart` event to allow deferrable `update()`

In many complex applications the first question that is asked is how can I asynchronously request user information before any `$stateChangeStart` events trigger. Whether it be to incorporate route protection, configuration, redirection etc.

This proposed pull request seeks to answer that question by exposing a new event `$urlRouterUpdateStart` which can cancel `$urlRouter#update()` with `preventDefault()`. `update()` is then referenced in the `$urlRouterUpdateStart` event listener and can be called asynchronously/synchronously.

The following example deferrers `update()` for 2000ms using `$timeout` asynchronously. The listener's deregistration function is assigned to `$off` and called when the listener is fired so that the listener will only defer `update()` once.
```javascript
angular.module('app', ['ui.router']);
.run(function($rootScope, $timeout) {
var $off = $rootScope.$on('$urlRouterUpdateStart', function(evt, update) {
evt.preventDefault();
$timeout(update, 2000);
$off();
});
});
```