In my angular 2 projects, I wasn't able to reload the page by navigating to the same URL but with different query params. I am using resolve to pre-fetch data upon loading the page.
I am trying to get the resolver to re-fetch the data when there's URL (query param) change. How do I do this?
Now you can with this in your route config:
{
path: '',
resolve: {
data : DataResolver,
},
runGuardsAndResolvers: 'paramsOrQueryParamsChange',
component: MainComponent
}
Passing the 'paramsOrQueryParamsChange' in your route config will trigger the DataResolver
at each params or queryParams change.
you can get the resolvers data in your MainComponent
like this:
ngOnInit() {
this.activatedRoute.data.subscribe((resolversData) => {
// is now triggered at each queryParams change
})
}
see the doc for more info
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With