Reputation: 1076
I try to create a view in Angular 2 that should look like this:
releases-component
----------------- ------------- --------------
| releases-list | | rcs-list | | binaries- |
| * release1 | | * rc1 | | list |
| release2 | | rc2 | | |
----------------- ------------- --------------
where each of the three parts is a component, whereas releases
and rcs
contains a list with links that should map to the following routes:
releases
-> list all releases in the releases
componentreleases/:id/rcs
-> lists rcs for the release with id in the rcs
componentreleases/:id/rcs/:no/binaries
-> lists binaries of the choosen rc
in the binaries
componentreleases-component.html
<router-outlet></router-outlet>
<router-outlet name="rcs"></router-outlet>
<router-outlet name="binaries"></router-outlet>
routes
{
path: 'releases',
component: ReleasesComponent,
children: [
{ path: '', component: ReleasesListComponent },
{
path: ':id/rcs',
outlet: 'rcs',
component: CandidateComponent,
children: [
{ path: ':no/binaries', outlet: 'binaries', component: BinariesComponent }
]
},
]
}
releases links - to show list of rcs
{outlets: {rcs: release.id + '/rcs'}}
rcs links - to show list of binaries
{outlets: {binaries: rc.id + '/binaries'}}
I have tried all different kind of route and link definitions, but I can't get it to work. With this current solution the binaries simply do not get displayed and after clicking another rcs
link I get the following error:
TypeError: Cannot read property 'component' of null
Upvotes: 1
Views: 614
Reputation: 39482
This might sound ridiculously complex. But it's fairly simple. I suggest you have your routing like this:
{ path: 'releases', component: ReleaseListComponent, children: [
{ path: '', component: NotSelectedComponent },
{ path: ':id', component: ReleaseDetailsComponent, children: [
{ path: '', component: NotSelectedComponent },
{ path: 'rcs', component: RcsListComponent, children: [
{ path: '', component: NotSelectedComponent },
{ path: ':id', component: RcsDetailsComponent, children: [
{ path: '', component: NotSelectedComponent },
{ path: 'binaries', component: BinaryListComponent }
] }
] }
] }
] }
Now for each path that has a component with children on it, you'll have to place a <router-outlet></router-outlet>
. And then it will figure out the rest on it's own.
So, by that I mean that following components will have a router-outlet
inside their templates:
ReleaseListComponent
ReleaseDetailsComponent
RcsListComponent
RcsDetailsComponent
I wish I could style this to show you on the screen. But that's too much of effort and I would literally be spoon-feeding you in that case.
But here's how it will look on the UI:
Upvotes: 1