Reputation: 1440
I'm not sure why, but the navigation to the home page after login is working most times. Occasionally, however, the app will stay on the login page and not load the home page as it should.
I added .then and console.logs but even when it failed I get 'navigation successful' in the console. I'm not sure what else to look for. It works probably 75% of the time, but I get nothing in the console when it fails to explain why.
When it fails there is no message in the console, no error that I can see, the page view stays on the login form, the address bar of the browser doesn't change and to top it off I DO get the toast message right above it. I've also tried moving the toast to after the navigate call, and will still get the toast even when it doesn't navigate. So I don't think the toastService is affecting it in any way.
public submitLogin(Login) {
this.loginService.login(Login.value.email, Login.value.password)
.subscribe(
() => {
this.toasterService.pop('success', 'Login', 'Successfully logged in');
this.router.navigate(['./home']).then(
() => console.log('navigation successful'),
() => console.log('navigation failed')
);
},
err => {
this.error = ApiHelper.buildErrorStringFromResponse(this.Login.controls, err);
}
);
}
Upvotes: 4
Views: 806
Reputation: 1440
I found the solution is because I wasn't using .share() and so the subscribes weren't always being executed in a fixed order. To the original http call I added .share() before adding the subscribes and now it always runs correct.
Upvotes: 1