Here is my resolver
@Injectable()
export class FieldsResolver implements Resolve<string[]> {
private result:Array<string> | null = null;
constructor(private httpClient:HttpClient) {}
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot){
return this.result || this.httpClient.get<Array<string>>('<api_route>')
.pipe(
tap(fields => {
this.result= fields;
})
);
}
}
As you can see, the data returned by the resolver does not depend on my route. Thus, I don't need to actually do the request to my API every times the route change.
My code above works : it does the request only the first time. And for the next few times it will return the cached result.
I was just wondering if there was a more rxjx way to do that.