Want to use async guard in Angular? You cannot return anything from subscribe, use map instead, also you need to add a return statement.
1 2 3 4 5 6 7 8 9 10 11 12 13 | canActivate() { // add 'return' return this.globalVarsService.getAgreeState() // change this! // .subscribe(state => { .map(state => { if(!state) { this.router.navigate(['/agree']); return false; } return true; }); } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.