I want to be able to use the same router-outlet for some routes.
Routing setup (simplified):
export const routes: Routes = [
{
path: 'app', component: AppComponent,
children: [
path: 'category/:id', component: CategoryComponent,
children: [
{ path: 'post/:id', component: PostComponent }
]
]
}
];
For example we have this path:
/app/category/1/post/1
That breaks into
/app - AppComponent
|_ /catory/1 - CategoryComponent
|_/post/1 - PostComponent
The AppComponent has a <router-outlet> which renders CategoryComponent,
but should also render the PostComponent when that route is active.
Common answers for this type of question:
Move the child routes and add them in the app-route children array
No. This isn't the right way. We still want our hierarchy of routes. CategoryComponent may know something which PostComponent doesn't - Such as Breadcrumb naming
So we still want our CategoryComponent to load. (Even if it's view isn't renders)
Use a <router-outlet> inside of CategoryComponent
No. The CategoryComponent should not be in charge of it's own <router-outlet>.
The PostComponent should be rendered in place of the CategoryComponent, and add CSS to place it like that should be illegal.
How can I acheive this behaviour?
Do i need to write my own router-outlet?
Will this be solved in Angular4?
Any tips are welcome! Thanks