重新解析查询参数更改后的数据? [英] re-resolving data upon query parameter change?
问题描述
在我的angular 2项目中,我无法通过导航到相同的URL但使用不同的查询参数来重新加载页面.我正在使用 resolve 来在加载页面时预提取数据.
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.
我正在尝试让解析器在URL(查询参数)发生更改时重新获取数据.我该怎么办?
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
}
在路由配置中传递"paramsOrQueryParamsChange"将在每个参数或queryParams更改时触发DataResolver. 您可以像这样在MainComponent中获取解析器数据:
passing '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
})
}
这篇关于重新解析查询参数更改后的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!