I have two components, a list and a detailed view. On clicking an item on the ListComponent I'd like to hand the current data set over to the Detailed component. The idea behind this, is that if the data is already available the DetailedComponent does not has to refetch it through the service.
Is it possible to add an object to routerLink which the DetailedView than gets onInit()?
eg.
router
...
{ path: 'hero/:id', component: HeroDetailComponent }
ListComponent
onSelect(hero: Hero) {
this.router.navigate(['/hero', hero.id]); // how to add hero as heroData
}
DetailComponent
ngOnInit() {
if( this.route.params.heroData ) {
this.hero = heroData // < this is what i like to do.
} else {
this.route.params
// (+) converts string 'id' to a number
.switchMap((params: Params) => this.service.getHero(+params['id']))
.subscribe((hero: Hero) => this.hero = hero)
}
}
I do know about angular 2 custom route parameters however they expose all the data and make it manipulatable or even old data is used if the url is kept. Thus this is not the they I'd like to go.