I use angular-cli for my application and I have a login page and here is the handler to submit it:
onSubmit() {
this.authService.login(this.uname.value, this.pass.value)
.subscribe(
(user: User) => {
this.username = user.username;
localStorage.userExist = true;
this.route.navigate(['/office/1']);
},
(err) => {
this.errorFromServer = err.error;
});
}
After submission, I expect that I would be redirected to localhost:3000/office/1
, but instead, I get an error:
GET http://localhost:3000/api/plan net::ERR_CONNECTION_RESET.
http://localhost:3000/api/plan provides information about office plan and I get this data with help of PlanResolver. Actually, I can get this data when I switch between offices, but it doesn’t work when I try to redirect from login page. So, maybe, something wrong with navigation inside subscription.
I have two resolvers that should be executed before navigation:
{path: 'office/:id', component: OfficesComponent,
resolve: {cres: OfficeResolver, plan: PlanResolver},
canActivate: [AuthGuardService]},
When I had one resolver, it worked fine, so I decided to combine two resolvers into one with forkJoin, but I got the same error.
The only one solution I have now is putting navigation in SetTimeout:
setTimeout(() => {
this.route.navigate(['/office/1']);
}, 500);
If you have any ideas what is wrong please tell me.
Thanks all.