Skip to content

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

@Roman-Simik

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 Angular@14.0.5 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: npm@8.19.2
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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: routerregressionIndicates than the issue relates to something that worked in a previous version

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions