Angular路由器:从navigationbyurl返回的Promise将被忽略

Sam*_*mmy 6 promise angular-routing angular

使用此代码:

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

我收到以下警告:从navigationbyurl返回的promise被忽略。我想在何时何地兑现承诺?

PS我正在AuthGuard的中使用它canActivate

小智 10

navigateByUrl 函数返回一个承诺,因此您可以使用 .then() 方法:

this.router.navigateByUrl('/login').then(() => {
    // Do something 
});
Run Code Online (Sandbox Code Playgroud)