1

I perform my searching from the navbar component at the top of the page. I can route to my 'member' component page when entering the search criteria from the navbar, but once I'm on the 'member' component and I change the query params and try to run the router.navigate() again I can't get Angular to hit my resolver.

here is what I do and what I tried above the navigate call, neither shouldReuseRoute or onSameUrlNavigation seem to work to hit my resolver again once on the component.

Question is - should it? Because maybe I have something else wrong somewhere!

// tried with no luck
this.router.routeReuseStrategy.shouldReuseRoute = () => false;
// tried with no luck
this.router.onSameUrlNavigation = 'reload';
this.router.navigate(['/members'], {
  queryParams: {
    latitude: this.locationLatitude,
    longitude: this.locationLongitude,
    gender: this.gender,
    minAge: this.ageFrom,
    maxAge: this.ageTo,
    orderBy: this.orderBy
  }
});
chuckd
  • 13,460
  • 29
  • 152
  • 331

3 Answers3

3

Routes can have the runGuardsAndResolvers property set to always to always run guards and resolvers on navigation. By default they run when the route or route params change.

{
  path: 'some/path/:and/:id',
  component: MemberComponent,
  ...
  runGuardsAndResolvers: 'always'
}
Preda7or
  • 328
  • 2
  • 7
0

You will need to subscribe to the query params change

constructor(
    private activatedRoute: ActivatedRoute,
) { }

this.activatedRoute.queryParams.subscribe(params => {
    console.log(params);
    // logic after subscribing
});

so basically anytime you change the queryParams it will fire that subscription and you can run your logic from there

Smokey Dawson
  • 8,827
  • 19
  • 77
  • 152
0

Actually, resolvers are called in those situations. You can check it simply by debugger. I had a similar problem recently and it occurs that I had a bug in my resolver and another one in component (as @smokey-dawson wrote - I missed subscription on route.data in my case)

kaff
  • 1