function when(url, route) {
    /*jshint validthis: true */
    if (route.redirectTo != null) {
      // Redirect, configure directly on $urlRouterProvider
      var redirect = route.redirectTo, handler;
      if (isString(redirect)) {
        handler = redirect; // leave $urlRouterProvider to handle
      } else if (isFunction(redirect)) {
        // Adapt to $urlRouterProvider API
        handler = function (params, $location) {
          return redirect(params, $location.path(), $location.search());
        };
      } else {
        throw new Error("Invalid 'redirectTo' in when()");
      }
      $urlRouterProvider.when(url, handler);
    } else {
      // Regular route, configure as state
      $stateProvider.state(inherit(route, {
        parent: null,
        name: 'route:' + encodeURIComponent(url),
        url: url,
        onEnter: onEnterRoute,
        onExit: onExitRoute
      }));
    }
    routes.push(route);
    return this;
  }
@ngdoc function
@name ui.router.compat.$routeProvider#when
@methodOf ui.router.compat.$routeProvider

@description
Registers a route with a given route definition object. The route definition
object has the same interface the angular core route definition object has.

@example
<pre>
var app = angular.module('app', ['ui.router.compat']);

app.config(function ($routeProvider) {
  $routeProvider.when('home', {
    controller: function () { ... },
    templateUrl: 'path/to/template'
  });
});
</pre>

@param {string} url URL as string
@param {object} route Route definition object

@return {object} $routeProvider - $routeProvider instance