Skip to content

Router.navigate doesnt work with relative route unless that route is currently active #38276

@slubowsky

Description

@slubowsky

🐞 bug report

Affected Package

The issue is caused by package @angular/router

Is this a regression?

Dont know

Description

When using Router.navigate and passing a relative route in NavigationExtras, navigation silently fails unless the relative route is CURRENTLY active. Documentation does not state that relativeTo route must currently be active (though the class type is called ActivatedRoute), that restriction would seem to be unwanted, and in any event a silent failure to navigate is certainly not expected behavior.

🔬 Minimal Reproduction

https://github.com/slubowsky/router-test

  1. Run app.
  2. Navigate to one by clicking the "one" button. This sets up a navigation function in NavigationService to perform navigation when called.
  3. Click "Go to three using navigation service" button. The navigation function is called and app successfully navigates as expected.
  4. Navigate to two by clicking the "two" button.
  5. Click "Go to three using navigation service" button. The same navigation function that previously successfully navigated is called again but this time app silently fails to navigate.

🔥 Exception or Error

🌍 Your Environment

Angular Version:


Angular CLI: 10.0.4
Node: 14.6.0
OS: win32 x64

Angular: 10.0.5
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router, service-worker
Ivy Workspace: Yes

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.1000.4
@angular-devkit/build-angular     0.1000.4
@angular-devkit/build-optimizer   0.1000.4
@angular-devkit/build-webpack     0.1000.4
@angular-devkit/core              7.3.10
@angular-devkit/schematics        7.3.10
@angular/cdk                      10.1.1
@angular/cli                      10.0.4
@ngtools/webpack                  10.0.4
@schematics/angular               8.3.28
@schematics/update                0.1000.4
rxjs                              6.6.0
typescript                        3.9.7
webpack                           4.43.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions