I am trying to navigate back to a home page within .then() after a promise but it does not seem to redirect. I have added a console log to see if this block is reached and I can confirm it is reached.
This code is within a service in an angular project, version 11.
I even tried to use ngzone which a few people suggested but this did not seem to resolve the issue.
Attempt 1 without ngzone:
if (this.authService.isAuthenticated()) {
this.logService.info('Refreshing auth token...');
this.authService
.refreshAccessToken()
.toPromise()
.then(() => {
// ISSUE IS HERE, NOT NAVIGATING TO '/'
this.router.navigate(['/']);
this.isLoading = false;
});
}
Attempt 2 with ngzone:
if (this.authService.isAuthenticated()) {
this.logService.info('Refreshing auth token...');
this.authService
.refreshAccessToken()
.toPromise()
.then(() => {
// ISSUE IS HERE, NOT NAVIGATING TO '/'
this.zone.run(() => this.router.navigate(['/']););
this.isLoading = false;
});
}
Please feel free to ask any questions and it would be much appreciated if any answers would have explanations.