Skip to content

Navigation events are called twice when using HashLocationStrategy #16710

Closed
bitwarden/clients
#1935

Description

@TetianaP

I'm submitting a ... (check one with "x")

[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior
When using HashLocationStrategy and change url manually to the one, which is protected by CanActivate guard (this returns false and fire redirect to the other page), navigation events are called twice.

Expected behavior
All navigation event are called once only.

Minimal reproduction of the problem with instructions
Use the demo in http://plnkr.co/edit/4xlYD9wmetG5G0Dvjp0E?p=preview
Open window mode http://run.plnkr.co/plunks/4xlYD9wmetG5G0Dvjp0E/#/component-one
Click Guarded Component Two link - only one NavigationStart and NavigationCancel events logged in console.
Manually change url from /#/component-one to /#/component-two and hit enter - two pair of NavigationStart and NavigationCancel events logged in console.

What is the motivation / use case for changing the behavior?
As the duplication of navigation event causes guards logic to be executed twice (and this may contain API calls) - it is a performance issue. Potentially, if guard resolving depends on some conditions which are true after first failed attempt - the second one will be successful, however it is not desired behavior.

Please tell us about your environment:

  • Angular version: 4.1.0

  • Browser: Chrome 57

  • Language: TypeScript

Activity

  1. self-assigned this
    on May 11, 2017
  2. IAMtheIAM commented on Oct 12, 2017

    @IAMtheIAM

    No activity or solution in months? This bug still exists. @jasonhodges Is this still on Angulars radar? Its a significant bug, in my opinion.

    Duplicate issue at #18366

  3. added this to the Backlog milestone on Jan 23, 2018
  4. lifenautjoe commented on Jan 29, 2018

    @lifenautjoe

    Getting five NavigationEnd events fired when

    router.events.subscribe((val) => {
                if (val instanceof NavigationEnd) {
                    console.log('NavigationEnd!');
                }
            });
  5. blackrek commented on Feb 12, 2018

    @blackrek

    have same problem.
    i planning update to 5 version, maybe this will help

  6. IraErshova commented on Feb 23, 2018

    @IraErshova

    Have the same problem. Use Angular version: 5.2.2 and Typescript 2.6.2

  7. aerlijman commented on Apr 3, 2018

    @aerlijman

    Same here with Angular 5.
    Any update on this?
    I pretty sure this issue is braking the back button click in the browser getting A->B->C and looping between B and C with the back button click in browser.

  8. harlenalvarez commented on Apr 5, 2018

    @harlenalvarez

    I have the same problem. Angular version 5.2.9

  9. Dhamu143 commented on Apr 10, 2018

    @Dhamu143

    is there any update ??

  10. padilla-jm commented on Apr 13, 2018

    @padilla-jm

    I am able to work around this issue but I am also very interested in a fix.

  11. rinkeshmistry commented on Apr 24, 2018

    @rinkeshmistry

    @jfox459 can u please provide your work around ?

  12. 58 remaining items

  13. angular-automatic-lock-bot commented on Aug 13, 2020

    @angular-automatic-lock-bot

    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.

  14. locked and limited conversation to collaborators on Aug 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions