Answer the question
In order to leave comments, you need to log in
How to know if a redirect went through in routerLink Angular 4?
Hello. I have a component that has a form. For this component, I set guard canDeactivate which blocks navigation to other pages if the form is not submitted. The problem is that I have a link to log out of my account:
<a routerLink="/login" (click)="logout($event)">Logout</a>
logout(event) {
this.authService.logout();
}
Answer the question
In order to leave comments, you need to log in
<button (click)="showConfirmLogout()">Logout</button>
public showConfirmLogout(): void {
this._confirmService.open('Вы действительно хотите выйти?').then(() => {
this._logout();
});
}
private _logout(): void {
this._authService.logout().subscribe(() => {
this._router.navigate(['/login']);
});
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question