-
Notifications
You must be signed in to change notification settings - Fork 27.2k
bug: relative navigation doesn't work inside route guards #22763
Copy link
Copy link
Closed
Labels
P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentAn issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: routerbreaking changesfeatureLabel used to distinguish feature request from other issuesLabel used to distinguish feature request from other issuesfeature: under considerationFeature request for which voting has completed and the request is now under considerationFeature request for which voting has completed and the request is now under considerationfreq3: highrouter: URL parsing/generationrouter: guards/resolvers
Milestone
Metadata
Metadata
Assignees
Labels
P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentAn issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: routerbreaking changesfeatureLabel used to distinguish feature request from other issuesLabel used to distinguish feature request from other issuesfeature: under considerationFeature request for which voting has completed and the request is now under considerationFeature request for which voting has completed and the request is now under considerationfreq3: highrouter: URL parsing/generationrouter: guards/resolvers
I'm submitting a...
Current behavior
Inside a route guard, injecting
ActivatedRouteand attempting relative navigation viathis.router.navigate(['../sibling'], {relativeTo: this.route})results in aError: Cannot match any routes. URL Segment: 'sibling'Expected behavior
Relative navigation should work normally
Minimal reproduction of the problem with instructions
A stackblitz example of the issue can be seen here: https://stackblitz.com/edit/angular-gitter-k7fjds
What is the motivation / use case for changing the behavior?
Additional Information
It appears that the
ActivatedRouteinjected into a route guard is always an instance of the root route. Inside a route guard,this.router.navigate(['.'], {relativeTo: this.route})always takes the user back to the root route, rather than navigating them to the same route they are currently on.Environment