Angular2 female socket

I play with Angular 2 and I am having problems with the router. I want to have a second router output inside the main router.

Inside the first exit of the router, I am redirected to the home page, where I have a second router:

<router-outlet name="main"></router-outlet> 

This app.routing application without import.

 const appRoutes: Routes = [ { path: '', component: HomeComponent }, { path: 'login', component: LoginComponent}, { path: 'days', component: DaysComponent, outlet: 'main'} ]; export const appRoutingProviders: any[] = [ ]; export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes); 

In HomeComponent ngOnInit, I have this

 this.router.navigateByUrl('/(main:days)'); 

But this leads to a network failure with the following error:

Unprepared (in promise): Error: Unable to find the main outlet for downloading "DaysComponent"

How could a second router output inside the main one?

Thanks.

+8
angular angular2-routing
source share
1 answer

Try this route configuration:

 const appRoutes: Routes = [ { path: '', component: HomeComponent }, { path: 'login', component: LoginComponent}, { path: 'wrap', component: HomeComponent, children: [ { path: 'days', component: DaysComponent, outlet: 'main' } ] } ]; 

and this url:

 this.router.navigate(['/wrap', { outlets: { main: 'days' } }]); 

or (equivalent)

 this.router.navigateByUrl('/wrap/(aux:aux)'); 
+9
source share

All Articles