Skip to content

fix(router): child CanActivate guard should wait for parent to complete - #15672

Closed
DzmitryShylovich wants to merge 1 commit into
angular:masterfrom
DzmitryShylovich:gh/15670
Closed

DzmitryShylovich wants to merge 1 commit into
angular:masterfrom
DzmitryShylovich:gh/15670

Conversation

@DzmitryShylovich

@DzmitryShylovich DzmitryShylovich commented Mar 31, 2017 •

Copy link
Copy Markdown
Contributor

@vicb

vicb commented Mar 31, 2017

Copy link
Copy Markdown
Contributor

LGTM, could you please add a test

@vicb vicb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a test

@DzmitryShylovich

Copy link
Copy Markdown
Contributor Author

@vicb added a test. I'm afraid in this case I can't avoid playing with timings.

@nrgonzalez777

Copy link
Copy Markdown

@DzmitryShylovich I ran into the bug that this changeset is attempting to solve and I can confirm that this change does force the guards to activate in the correct order. However, this change seems to also cause a more subtle error to occur.

I have a guard defined that in the case of an error is supposed to navigate to the root of my application. Before making the change from mergeMap to concatMap the navigation on error seems to work fine. Unfortunately after swapping out the functions in the Angular source code the navigate no longer navigates back correctly. While it doesn't throw any errors, the root application page no longer renders.

canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
        var success = false;
        var productId = route.params['productId'];

        success = this.ngRedux.getState().products.find(p => p.id === productId) !== undefined;

        if (success) {
            this.pageActions.updatePageState({ productId: productId });
        }
        else {
            this.router.navigate(['/']);
        }

        return success;
    }

@DzmitryShylovich

Copy link
Copy Markdown
Contributor Author

@nrgonzalez777 can you please provide a small plunkr with the code that does work before the fix and doesn't work after? Because I can't reproduce.

@angular-automatic-lock-bot

Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot Bot locked and limited conversation to collaborators Sep 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CanActivate guards on child routes run before parent CanActivate guards finish

5 participants