admin管理员组文章数量:1433963
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)
本文标签: javascriptAngular routernavigate doesn39t route to resolver if on same componentStack Overflow
版权声明:本文标题:javascript - Angular router.navigate doesn't route to resolver if on same component - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745606423a2665863.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论