title: Angular Router: navigateByUrl() resolving with false
body: <p>According to Angular's documentation of <a href="https://angular.io/docs/ts/latest/api/router/index/Router-class.html#!#navigateByUrl-anchor" rel="nofollow noreferrer"><code>navigateByUrl</code></a>, it returns a promise that will resolve with <code>true</code> or <code>false</code>, depending on whether the navigation succeeded or failed. If an error happens, the promise will be rejected with an error.</p>
  
  <p>I am trying to use <code>navigateByUrl</code> within an <code>AuthGuard</code> service to navigate the user to their original URL after successful authentication. However, the navigation fails, and the promise is resolved with <code>false</code>. It is not rejected. There is no further information on why it fails.</p>
  
  <p>I have verified that the guard returns <code>true</code> when triggered via the <code>navigateToUrl()</code> call.</p>
  
  <p>Here's the full code for <code>AuthGuard</code>:</p>
  
  <pre><code>import { Location } from '@angular/common';
  import { Injectable } from '@angular/core';
  import { CanLoad, Router } from '@angular/router';
  
  import { AuthService } from './auth.service';
  
  @Injectable()
  export class AuthGuard implements CanLoad {
    public constructor(
      private authService: AuthService,
      private router: Router,
      private location: Location,
    ) { }
    public canLoad() {
      return this.authService.validateToken()
        .map(isAuthenticated =&gt; ({
          isAuthenticated,
          willRedirect: this.manageRedirect(isAuthenticated),
        }))
        .do(result =&gt; {
          if (!result.isAuthenticated) {
            // will navigate away from Angular application to OAuth page
            this.authService.startLogin();
          }
        })
        .map(result =&gt;
          result.isAuthenticated &amp;&amp; !result.willRedirect);
    }
  
    private manageRedirect(isAuthenticated: boolean) {
      let willRedirect = false;
  
      if (isAuthenticated) {
        const redirectUri = sessionStorage.getItem('redirectUri');
        sessionStorage.removeItem('redirectUri');
  
        if (redirectUri) {
          willRedirect = true;
          this.router.navigateByUrl(redirectUri).then(success =&gt; {
            console.log(success);  // false!!
          });
        }
      } else {
        const redirectUri = this.location
          .prepareExternalUrl(this.location.path());
  
        sessionStorage.setItem('redirectUri', redirectUri);
      }
  
      return willRedirect;
    }
  }
  </code></pre>
  
  <p>Please note that if I delay the <code>navigateByUrl</code> call with a timeout of about 1 second, the navigation will work.</p>