Thank you for spending time here.
So Im having little problem with canDeactivate. I made a page If I click go-back button, there will be a modal show up, And user can choose either escape that page or not. Which is works fine If I click only once. But here is the problem. Lets say I was located at [ page A -> page B -> page C ] and on page C, I put canDeactivate. So If I click Ok on Modal when I click go-back, It moves to page B well. But If I click Cancel on Modal first and click go-back again, When I click Ok, It moves to page A. Certainly Whenever I call canDeactivate, It acts like It already moved no matter what I click on modal.
So All I wanna do is no matter how many times I call canDeactivate, When I click Ok on modal, I want to move to Page B. Hope y'all have solution for me.
canDeactivate.file
export class DeactiveGuard implements CanDeactivate<GrammarComponent> {
constructor(private router: Router) {}
canDeactivate(component: GrammarComponent) {
return component.canDeactivate ? component.canDeactivate() : true
}
}
page C.file
public canDeactivate() {
if (!this.exceptCanDeactivate) {
return from(
this.modalService.open(this.exitFromExamMd, {
centered: true,
scrollable: true,
windowClass: 'final-confirm',
}).result,
).pipe(map((result) => result === 'yes'))
} else {
return true
}
}