title: How to defer routes definition in Angular.js?
body: <p>I have configured some basic routes that are available for all users before they log in:</p>
  
  <pre><code>App.config(function ($routeProvider) {
      $routeProvider.
          when('/login', { templateUrl: 'views/login.html', controller: PageStartCtrl.Controller }).
          otherwise({ redirectTo: '/login' });
  });
  </code></pre>
  
  <p>So the only thing user can do is to log in. After the user logs in, I would like to register additional routes like this:</p>
  
  <pre><code>$http
    .post('api/Users/Login', {   User: userName, Password: userPassword })
    .success(function (response : any) {
      App.config(function ($routeProvider) {
        $routeProvider
          .when('/dashboard', 
                { templateUrl: 'part/dashboard.html', 
                controller: DashboardCtrl.Controller });
    });
  </code></pre>
  
  <p>However, I suppose I should call .config method only once, because the $routeProvider is brand new instance that knows nothing about /login route. Further debugging showed me that the first instance of $resourceProvider is used when resolving view change.</p>
  
  <p>Q: Is there a way how to register routes later?</p>
  
  <p>Solution from <a href="https://groups.google.com/d/msg/angular/mrcy_2BZavQ/Mqte8AvEh0QJ" rel="noreferrer">Add routes and templates dynamically to $routeProvider</a> might work, but is quite ugly (involved global variable <code>nastyGlobalReferenceToRouteProvider</code>).</p>