Problem with more than two in-app router

0
[...]
<header>
     <a routerLink="/lista-empresa" href="javascript:;">Empresa</a>
</header>
[...]
<main>
<router-outlet name="conteudo"></router-outlet>
</main>
[...]

empresa.routing.module.ts

const empresaRoutes: Routes = [
    {
        path: '',
        component: EmpresaListasComponent,
        outlet: 'conteudo'
    }
]

@NgModule({
    imports: [RouterModule.forChild(empresaRoutes)],
    exports: [RouterModule]
})
export class EmpresaRoutingModule { }

app.routing.module.ts

const ROUTES:Routes=[
    {path:'', component:PrincipalComponent},
    {path:'lista-empresa', loadChildren:'app/empresa/empresa.module#EmpresaModule'}
];
@NgModule({
    imports:[RouterModule.forRoot(ROUTES)],
    exports:[RouterModule]
})
export class RoutingModule{}

app.component.html

<router-outlet></router-outlet>

Now let's get into the problem. When you click routerLink , the component that should be rendered in outlet=Conteudo does not work as expected. The page is left blank.

From what I understood in my research, giving a name to my router-outlet . The component should be rendered inside it. Where am I going wrong?

Note: This is the Sun after selecting the lista-empresa

    
asked by anonymous 05.01.2018 / 22:23

1 answer

0

I put my CompanyComponent as the child of PrincipalComponent and removed the router's outlet parameter, removed the name attribute from <router-outlet></router-outlet> , and resolved.

Loads the enterprise component as the child of PrincipalComponent

 const PRINCIPAL_ROUTES: Routes = [
    {path: '', component: PrincipalComponent, 
    children:[
        {path: '', loadChildren: 'app/empresa/empresa.module#EmpresaModule'},        
    ]},

];

and in the main main component

<router-outlet></router-outlet>

Full discussion in stackoverflow English here

    
08.01.2018 / 16:04