I have implemented a route resolver in this manner, where I want to make two additional HTTP requests based on the initial response from forkjoin. I attempted to nest another forkjoin inside the first one, but I am open to suggestions on better approaches to handle such scenarios. My ultimate goal is to merge both responses into a single unit.
resolve(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot
): Observable<any> {
const userDetails = this._spotify.getCurrentUser();
const newReleases = this._spotify.getNewReleases();
const recentPlayedTrack = this._spotify.getUserRecentlyPlayedTracks();
const resolvedData = forkJoin([
userDetails,
newReleases,
recentPlayedTrack
]).pipe(
map((dashboardApiResults) => {
const url = `...${dashboardApiResults[1].id}`;
const options = {
useUrlPrefix: false
};
const req1 = this._http.get(url, options);
const req2 = this._http.get(url, options);
const requests = forkJoin([req1, req2]);
return {
userDetails: dashboardApiResults[0],
newReleases: dashboardApiResults[1],
recentPlayedTracks: dashboardApiResults[2]
};
})
);
return resolvedData;
}