title: Call function at the end of Router.navigate
body: <p>I want to call a certain function after a user logs in. The user may log in from any page and on a successful log in, the user is redirected back to the previous page that they were browsing.</p>
  <p>I'm using <a href="https://angular.io/api/router/Router#navigate" rel="nofollow noreferrer">Router.navigate</a> for redirecting to the page.</p>
  <p>After looking for a while <a href="https://angular.io/api/router/NavigationEnd" rel="nofollow noreferrer">NavigationEnd</a> seems like an option which would work, but it applies to <em>all</em> router events, not just a specific one.</p>
  <p>My <code>login.component.ts</code> has something like this:</p>
  <pre><code>// ...
  this.authenticationService.login(this.credentials)
    .pipe(first())
    .subscribe(
      data =&gt; {
        this.router.navigate([this.returnUrl]);
        // Need to call a function `doSomething()` here.
      },
      error =&gt; {
        // Implement error handling
      });
  // ...
  </code></pre>
  <p>I know that it's not a promise but I'm looking for something like:</p>
  <pre><code>this.router.navigate([this.returnUrl])
    .then(this.doSomething()); // or .pipe()
  </code></pre>