New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

canDeactivate() is triggered twice #45

Closed
vizo opened this Issue Mar 13, 2015 · 7 comments

Comments

Projects
None yet
6 participants
@vizo

vizo commented Mar 13, 2015

canDeactivate() is triggered twice when you navigate to another route where canActivate returns new Redirect('...').

Is there any workaround?

@EisenbergEffect EisenbergEffect added the bug label Mar 17, 2015

@EisenbergEffect

This comment has been minimized.

Member

EisenbergEffect commented Mar 17, 2015

Hmmm. That is an interesting problem. I'll need to think a bit about it.

@flieks

This comment has been minimized.

flieks commented Oct 5, 2015

I also have the canDeactivate function exectued twice but i don't have a canActivate in the next route. When this problem happens, the deactivate function doesn't get triggered aldough the page is navigated away from.

note: ok seems the detached() was called instead. Which is a bit strange, because it's not an attribute or custom element. It's a base class which is overriden. In some/most situations it calls deactivate. In some it calls detached. I don't know why but cleanup works now.

@davismj

This comment has been minimized.

Member

davismj commented Jan 26, 2016

What is the desired behavior here? If AuthorizeStep throws a Redirect, does the AuthorizeStep need to be run again? if so, then a "pick up where you left off" strategy makes sense. If not, then perhaps we just want to prevent multiple calls to the same canDeactivate() per activation cycle?

@jeffgrann

This comment has been minimized.

jeffgrann commented Oct 16, 2017

I believe that I just ran into this as well. canDeactivate is triggered, then there is a redirect, and then canDeactivate is triggered again. Like @flieks, there is no canActivate for me either, so it has nothing to do with that. This has been a bug for over 2 years. I think the suggestion by @davismj is the way to go: prevent multiple calls to the same canDeactivate() per activation cycle.

@c350156378

This comment has been minimized.

c350156378 commented Oct 17, 2017

the same issue

@davismj davismj self-assigned this Oct 31, 2017

@davismj davismj closed this in #616 Aug 16, 2018

davismj added a commit that referenced this issue Aug 16, 2018

fix: Prevent running CanDeactivatePreviousStep twice in same navigation
To handle this, I've added a new parameter to the router called `couldDeactivate` which is set to true whenever the CanDeactivatePreviousStep completes and is reset on every navigation. If a redirect is returned from the CanActivateNextStep, then this value will be true and it is used to build a special pipeline that skips the CanDeactivatePreviousStep on the next pipeline run.

fixes #45
@EisenbergEffect

This comment has been minimized.

Member

EisenbergEffect commented Aug 16, 2018

Are we back-porting all of this to the TS conversion, so that we don't have a regression?

@davismj

This comment has been minimized.

Member

davismj commented Aug 16, 2018

Gunna update the TS conversion PR with changes here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment