Repository navigation
Description
I'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
Currently, when route parameters change, resolvers are executed, but there is no way of knowing which parameter has changed.
Lets say we have a route:
{
path: 'details/:firstId/:secondId',
component: Details,
resolve: { first: FirstResolver, second: SecondResolver }
}
When any of firstId or secondId changes, both FirstResolver and SecondResolver are executed.
Expected behavior
Firstly, we need a way to determine which parameter has changed.
Secondly, we need a way to return previously resolved value if the relevant parameter hasn't changed.
This can be archived with simple (from the user's point of view) change:
Route config should expect array of providers in canActivate, canDeactive, canActivateChild and canLoad properties and map of string => provider as resolve property.
This way, we don't need to provide guards at module level. The guard instance will be created when user wants to activate route, before the component instance is created and destroyed when user deactivates route.
Since guards will no longer be singletons (they will be unique per component instance), it would be possible to store in them some data, unique for the component, for example:
@Injectable()
export class DetailsResolver implements Resolve<any> {
private lastId: string = null;
private lastValue: any;
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) : Observable<any>|Promise<any>|any {
if (this.lastId === null || this.lastId === route.params['id']) {
// actual resolving
} else {
return this.lastValue
}
}
}
Minimal reproduction of the problem with instructions
http://plnkr.co/edit/Krok4FpJoTmm8fmdqUsi
What is the motivation / use case for changing the behavior?
To stop resolver from performing unnecessary ajax calls.
Please tell us about your environment:
- Angular version: 2.4.6
- Browser: all
- Language: all
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 25, 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 23, 2021
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.