Search code examples
angularpromiseangular-routing

Angular router: promise returned from navigatebyurl is ignored


Using this code:

this.router.navigateByUrl('/login');

I get the following warning: promise returned from navigatebyurl is ignored. How and when would I want to handle the promise here?

P.S. I'm using this in AuthGuard's canActivate.


Solution

  • The navigateByUrl function returns a promise so you can use .then() method :

    this.router.navigateByUrl('/login').then(() => {
        // Do something 
    });