Just a little new to Angular2 world, however it was preety simpler in angular 1 by specifying {reload: false} but not able to find a similar solution in Angular 2 where I can avoid reloading the component while changing the query param in my route.
I have html template, where I am changing the query parameter on click of a button.
I have the method updateRoute({type: 'app_dependency'}) which gets called on click of the button:
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
});
}
But every time this function gets called, it destroys the component and calls ngOnInit().
Is it possible to just change the url query (I am not changing the route but just changing the query) without reloading my component? If yes, can anyone please help me or suggest me a better approach.
activatedRoute.snapshotshould only be used if the component never gets reused (Angular Docs), what I think you're trying to achieve.navigate( [] , { skipLocationChange: true }):?