How to rerun resolvers when queryParams change

Viewed 7929

I'm working on it for days, But doesn't find any solution so far.

I've got a resolver service, which's supposed to return an Observable :

resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) : Observable<any>|Promise<any>{
    return Observable.forkJoin(
         this.http.get(first call with queryParam),
         this.http.get(second call with queryParam),             
    );
}

I subscribe to my ActivatedRoute data in the component, and it's working pretty well.

BUT, as you can see in the code above, my component has a queryParam, and my API calls depend on this queryParam. When I manually change it, it doesn't "resolve" the route again.

I completely understand why, I read the documentation.

Does anyone has a workaround ? Is this even possible to subscribe to params and return an Observable in this situation ?

I tried this so far, but it doesn't return an Observable, so it does nothing :

this.router.events.subscribe(event => { 
    if(event instanceof ResolveEnd){
      // My previous Observable.forkJoin
    }
});

Thank you :) !

----------- SOLUTION (thanks Maximus) : -----------

Add in the routing :

{
   path: 'some path',
   runGuardsAndResolvers: 'paramsOrQueryParamsChange'
   ...
}

Then, no need to subscribe to route event or anything ! Magic !

1 Answers
Related