Having these routes defined in app.module.ts
...
{ path: \'mypath\', component: MyComponent, canActivate: [RouteGuard] },
{ path: \'\', redirectTo: \'/home\
You're making an asynchronous call to your auth service, that means canActivate()
returns this.loggedIn
before it sets its value to true or false. And since the guard is called every time you take the 'mypath' route this.isLoggedin
will be reset to null
Now to avoid this behavior you can use a boolean outside of your guard and use that boolean to keep track of if you're logged in or not.