只是Angular2世界的一点点新东西,但是通过指定{reload:false}在角度1中更简单,但是无法在Angular 2中找到类似的解决方案,我可以避免在更改路径中的查询参数时重新加载组件 .
我有html模板,我点击按钮更改查询参数 .
我有方法updateRoute({type:'app_dependency'}),点击按钮后会调用它:
ngOnInit() {
console.log(`ngOnInit - is called. `);
}
public updateRoute(urlObject){
let queryParams = this.activatedRoute.snapshot.queryParams;
let updatedQuery = clone(queryParams);
this.activeTab = updatedQuery.type || 'app_dependency';
forEach(urlObject, (value, key) => {
updatedQuery[key] = value;
});
//this.location.search({type: 'app_dependency'})
this.router.navigate([], {
relativeTo: this.activatedRoute,
queryParams: queryParams
});
}
但每次调用此函数时,它都会销毁组件并调用ngOnInit() .
是否可以只更改url查询(我不更改路由,只是更改查询)而无需重新加载我的组件?如果是的话,任何人都可以帮助我或建议我一个更好的方法 .