Make resolves/guards injectable/gettable in other resolves/guards on the same level
See original GitHub issueI’m submitting a … (check one with “x”)
[ ] bug report => search github for a similar issue or PR before submitting
[x] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
Current behavior
In a resolve, we are able to get the data from resolves on the parents, but not from the same level, so we need to do:
[
{
canActivate: [PlannerForGuard],
canActivateChild: [PlannerForGuard],
children: [
{
canActivateChild: [PlannerForGuard],
children: [
{
canActivate: [RedirectToLastRunGuard],
canActivateChild: [PlannerForGuard],
children: [
{
component: RunsComponent,
path: 'runs/:runId',
resolve: {
deleteRun: DeleteRunResolve,
run: RunResolve
}
},
{
canActivate: [RedirectToLastRunGuard],
component: RunsComponent,
path: 'runs'
}
],
component: SimulationComponent,
path: '',
resolve: {
createRun: CreateRunResolve,
createSimulation: CreateSimulationResolve,
deleteSimulation: DeleteSimulationResolve
}
}
],
path: '',
resolve: {
runs: RunsResolve
}
}
],
path: '',
resolve: {
simulation: SimulationResolve
}
}
]
Expected behavior
This could be so much simplified if resolves/guards can ‘wait’ for other resolves/guards on the same level, like this (it will also make for less guard checks…):
[
{
canActivate: [PlannerForGuard, RedirectToLastRunGuard],
canActivateChild: [PlannerForGuard],
children: [
{
component: RunsComponent,
path: 'runs/:runId',
resolve: {
deleteRun: DeleteRunResolve,
run: RunResolve
}
},
{
canActivate: [RedirectToLastRunGuard],
component: RunsComponent,
path: 'runs'
}
],
component: SimulationComponent,
path: '',
resolve: {
createRun: CreateRunResolve,
createSimulation: CreateSimulationResolve,
deleteSimulation: DeleteSimulationResolve,
runs: RunsResolve,
simulation: SimulationResolve
}
}
]
What is the motivation / use case for changing the behavior?
It would allow for less, clearer code + less runs of guards + speed up resolving resolves (as it’s now done per level) + no more .parent.parent… to get the parent resolves (or a custom function to search for a resolve by name 😉)
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:18 (7 by maintainers)
Top Results From Across the Web
Router Guards • Angular - codecraft.tv
Guards are implemented as services that need to be provided so we typically create them as @Injectable classes. Guards return either true if...
Read more >Angular2 run Guard after another guard resolved
The best way I've seen it done is to expose the router guards on child routes. Here is a working example.
Read more >Angular Resolve Guard - TekTutorialsHub
The another way to solve this is to make use the Resolve Guard. The Resolve Guard pre fetches the data before the navigating...
Read more >Protecting Routes using Guards in Angular - Thoughtram Blog
Angular's router enables protecting routes using guards and in this article we're going to discuss how to implement them.
Read more >Resolver Guard in Angular Router (2021) - YouTube
In this #Angular tutorial you will know how to resolve your date before some certain route will be activated by using router resolver....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@DzmitryShylovich , nope, it need to be two resolves, as on other routes, I have them in different levels + they resolve to two separate observables. Putting them together will just end up in code duplication, which is very bad, as you have to make sure you edit it in all places… I use resolves to construct the app state, where some states depend on others, but the level they are on isn’t always known.
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.