I perform my searching from the navbar ponent at the top of the page. I can route to my 'member' ponent page when entering the search criteria from the navbar, but once I'm on the 'member' ponent 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 ponent.
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
}
});
I perform my searching from the navbar ponent at the top of the page. I can route to my 'member' ponent page when entering the search criteria from the navbar, but once I'm on the 'member' ponent 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 ponent.
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
}
});
Share
Improve this question
asked Jan 20, 2020 at 4:50
chuckdchuckd
14.7k34 gold badges179 silver badges397 bronze badges
3 Answers
Reset to default 5Routes 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',
ponent: MemberComponent,
...
runGuardsAndResolvers: 'always'
}
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
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 ponent (as @smokey-dawson wrote - I missed subscription on route.data in my case)