I'm developing an Angular2 app and I would like to navigate from a component to another one passing some data. In my case I need to pass a configuration object that I use in the component that I navigate to for changing some behaviours according to that configuration object.
private goToOtherComponent(): void {
let options = {
checkboxes: true,
actions: ['save', 'close'],
items: ['foo', 'bar'],
clickable: false
};
this.route.navigate(['documents'], options)
.then(response => {
console.log('response', response);
})
.catch(error => {
console.log('error', error);
});
}
I have read some questions like mine and I have read Angular documentation, but I can't figure out how to do that.
RouteParamsis deprecatedqueryParamsis not what I'm looking forRouteSegmentI think is not suitable for my case- Using a shared service is a solution I do not like
Here is how I pass data in the routing ngModule file:
{path: 'documents', data: { someValue: 'foo', otherValue: 'bar' }
I would like to have a similar way to pass data using navigate method.
Then how to retrieve that options object in the component that I navigate to?