My CanDeactivateGuard
not always fires when I click browser back button.
I can't find the reason. Could you take a look at my code, and give me advice?
Guard:
@Injectable()
export class CanDeactivateGuard implements CanDeactivate<SignupComponent> {
canDeactivate(component: SignupComponent): boolean {
if (!component.canDeactivate()) {
if (confirm("You have unsaved changes! If you leave, your changes will be lost.")) {
return true;
} else {
return false;
}
}
return true;
}
}
Method in SignupComponent:
canDeactivate() {
if (this.activeStep == 'step1' || this.activeStep == 'step5') {
return true;
} else {
return false;
}
}
Routing:
...
{
path: 'signup/:nickname',
component: SignupComponent
},
{
path: 'signup',
component: SignupComponent,
canDeactivate: [CanDeactivateGuard]
},
...