Skip to content

Router events doesn't emit NavigationEnd event if previous navigation was cancelled #48052

Closed

Description

@Roman-Simik

Which @angular/* package(s) are the source of the bug?

router

Is this a regression?

Yes

Description

  • There's bug in Angular@>=14.0.5, where router.events doesn't emit NavigationEnd event if navigation was triggered while other was in progress, in addition to that it won't even update the url with the new value

  • This bug happens when trying to do router navigation while other navigation is in progress

  • Happens only if router config has set initialNavigation: 'enabledBlocking'

  • This bug was introduced in [email protected] which has only this single MR merged

How to reproduce: (pretty easily)

  • Try to do router.navigate() inside ngOnInit() hook in root component (AppComponent)

Minimal reproduction:

14.0.5 - bug introduced

  • In the console you can see events emitted in following order:
  1. NavigationStart (first app navigation)
  2. (RoutesRecognized, GuardsCheckStart, GuardsCheckEnd)
  3. AppComponent#ngOnInit navigation triggered
  4. NavigationCancel
  5. NavigationStart
  6. (RoutesRecognized, GuardsCheckStart, GuardsCheckEnd)
  • On the 7th step I would expect NavigationEnd should be emitted, so I would know that router navigation has been finished, otherwise I'm not able to know that

14.0.4 - working correctly

  • In the console you can see events emitted in following order:
  1. NavigationStart (first app navigation)
  2. (RoutesRecognized, GuardsCheckStart, GuardsCheckEnd)
  3. AppComponent#ngOnInit navigation triggered
  4. NavigationCancel
  5. NavigationStart
  6. (RoutesRecognized, GuardsCheckStart, GuardsCheckEnd)
  7. Navigation End & Scroll
  • As you see, in this version it correctly emits NavigationEnd event so I know, that navigation has been finished

Please provide a link to a minimal reproduction of the bug

See in description

Please provide the exception or error you saw

No error/exception is being thrown

Please provide the environment you discovered this bug in (run ng version)

Angular CLI: >= 14.0.5
Node: 18.10.0
Package Manager: [email protected]
OS: Windows 11 64bit
All Angular packages version: >= 14.0.5

Anything else?

  • If this change was intended, can anyone suggest, how can I in this case know, when the navigation has been finished?

Activity

  1. added this to the needsTriage milestone on Nov 14, 2022
  2. Treen11 commented on Nov 15, 2022

    @Treen11

    same here

  3. salopa commented on Nov 15, 2022

    @salopa

    +1

  4. atscott commented on Nov 15, 2022

    @atscott
    Contributor

    Thanks for the reproductions. I'll get this fixed today and it should be included in the releases tomorrow.

  5. added
    regression
    on Nov 15, 2022
  6. added a commit that references this issue on Nov 15, 2022
    aef353c
  7. added
    P3
    on Nov 16, 2022
  8. modified the milestones: needsTriage, Backlog on Nov 16, 2022
  9. added a commit that references this issue on Nov 17, 2022
    9baefd0
  10. angular-automatic-lock-bot commented on Dec 18, 2022

    @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.

  11. locked and limited conversation to collaborators on Dec 18, 2022
  12. added a commit that references this issue on Feb 1, 2023
    03edc0b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3area: routerregression

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions