Skip to content
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 · Fixed by #616
Closed

canDeactivate() is triggered twice #45

vizo opened this issue Mar 13, 2015 · 7 comments · Fixed by #616
Assignees
Labels

Comments

@vizo
Copy link

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
Copy link
Contributor

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

@flieks
Copy link

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
Copy link
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
Copy link

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
Copy link

the same issue

@davismj davismj self-assigned this Oct 31, 2017
davismj added a commit that referenced this issue Aug 16, 2018
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
Copy link
Contributor

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

@davismj
Copy link
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
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants