Populating a parent outlet in Angular2

I have the following routes defined in my .module application:

RouterModule.forRoot([
{
  path: 'main',
  component: MainComponent,
  loadChildren: 'mySidebar.module#SidebarModule      
}
])

inside SidebarModule I define a routes a:

RouterModule.forChild(
        [{
           path: 'sidebar1',
           component: SideBar1,
           outlet: sidebar
        },
        {
           path: 'sidebar2',
           component: SideBar2,
           outlet: sidebar
         }
       ])

and MainComponent:

..
<router-outlet></router-outlet>
<router-outlet name="sidebar"><router-outlet>
..

when I go to 'main/(sidebar:sidebar1)', I get this error:

"cannot find outlet sidebar to load SideBar1"

which is probably due to the fact that the child module does not know the sidebar output. I want to fill the sidebar with a different outlet (without exposing a specific component), is there a way to do this?

+4
source share

Source: https://habr.com/ru/post/1672660/


All Articles