You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Access failed ActivatedRouteSnapshot in NavigationError聽#27626
馃殌 Access failed ActivatedRouteSnapshot in NavigationError
Relevant Package
This feature request is for @angular/router. Specifically, /packages/router/src/router.ts.
Description
I have the following scenario:
user clicks a link to go to a new page
one of the resolvers for that page fails with a very specific error (let's say, missing permissions)
I listen on NavigationError events
I catch the NavigationError event. It contains the error raised in step 2 and the URL the user was trying to reach.
I'd like to be able to configure (in the route configuration) where to redirect the user when this specific error occurs. But I don't have the handle to ActivatedRouteSnapshot for the page the user was trying to reach, and so I cannot access its "data" property where I wrote the configuration.
A sample route configuration could look like this:
Ideally, I'd like the failed ActivatedRouteSnapshot to be a field of NavigationError. It's important for it to be the "leaf" ActivatedRouteSnapshot, not the root one, as it's in the leaf where I put my permissionConfig.
Describe alternatives you've considered
Currently I'm using the following workaround: I have a "fake" route guard, with a canActivate call that always returns of(true), but remembers its arguments (ActivatedRouteSnapshot and RouterStateSnapshot) on "global" variables that I can access later when handling the NavigationError elsewhere. I'm also clearing this global state every NavigationStart so that there's no risk of using the wrong snapshot later.
The downside of the workaround is that I have to add the fake guard to every @NgModule that uses permissionConfig. If I forget to do it, it doesn't work. And I cannot add my fake guard to the root @NgModule (to RouterModule.forRoot), because then the ActivatedRouteSnapshot I receive is the root snapshot and I have no means of knowing which of its children I should descend to to find my configuration (there can be multiple children because of outlets).
Thank you for submitting your feature request! Looks like during the polling process it didn't collect a sufficient number of votes to move to the next stage.
We want to keep Angular rich and ergonomic and at the same time be mindful about its scope and learning journey. If you think your request could live outside Angular's scope, we'd encourage you to collaborate with the community on publishing it as an open source package.
You can find more details about the feature request process in our documentation.
Activity
angular-robot commentedon Jun 4, 2021
Just a heads up that we kicked off a community voting process for your feature request. There are 20 days until the voting process ends.
Find more details about Angular's feature request process in our documentation.
angular-robot commentedon Jun 27, 2021
Thank you for submitting your feature request! Looks like during the polling process it didn't collect a sufficient number of votes to move to the next stage.
We want to keep Angular rich and ergonomic and at the same time be mindful about its scope and learning journey. If you think your request could live outside Angular's scope, we'd encourage you to collaborate with the community on publishing it as an open source package.
You can find more details about the feature request process in our documentation.
angular-automatic-lock-bot commentedon Aug 8, 2022
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.