Angular router: promise returned from navigatebyurl is ignored

Sammy picture Sammy · May 20, 2017 · Viewed 7.8k times · Source

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.

Answer

Amir BenAmara picture Amir BenAmara · Dec 22, 2020

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

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