I have to modules, where the secound module is lazy loaded during routing through auth. The main module app module with routing looks as following:
const app_routes: Routes = [
{ path: '', component: MainComponent, outlet: 'app', pathMatch: 'full',
canActivate: [OauthGuard]},
{ path: 'auth', loadChildren: 'app/authentication/authentication.module#AuthenticationModule'},
{ path: '**', component: PageNotFoundComponent, outlet: 'app' }
];
@NgModule({
declarations: [...],
imports: [RouterModule.forRoot(app_routes)],
providers: [OauthGuard],
bootstrap: [
AppComponent
],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
exports: [RouterModule]
})
export class AppModule {}
Here navigationg to auth loads the AuthenticationModule.
const auth_routes: Routes = [
{
path: '',
component: AuthenticationComponent,
outlet: 'app',
children: [
{ path: '', redirectTo: 'login', pathMatch: 'full' },
{
path: 'register',
component: RegisterComponent,
outlet: 'auth'
},
{
path: 'login',
component: LoginComponent,
outlet: 'auth'
}
]}
];
@NgModule({
imports: [
CommonModule,
RouterModule.forChild(auth_routes),
UtilsModule,
HttpModule
],
declarations: [
AuthenticationComponent,
RegisterComponent,
LoginComponent
],
exports: [
RouterModule
],
providers: [
ClientService,
AuthenticationService
],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
bootstrap: [
AuthenticationComponent
]
})
export class AuthenticationModule {
}
According to my logic LoginComponent should be loaded on the auth router-outlet when navigation to auth/login. But instead i get this error message:
Error: Cannot match any routes. URL Segment: 'auth/login'
As suggested i logged routes registered when canActivate()gets called on first route change getting this:
Routes: [
{
"path": "",
"outlet": "app",
"pathMatch": "full",
"canActivate": [
null
]
},
{
"path": "auth",
"loadChildren": "app/authentication/authentication.module#AuthenticationModule"
},
{
"path": "**",
"outlet": "app"
}
]
Routes registered are the same in the ran from the àuthentication.module` constructor.
I realy have no idea why i still get this error. Any tips?
{ path: 'auth', loadChildren: () => AuthenticationModule}does not do lazy loading. It to builds up the route tree using modules without lazy loading.outlet: 'app',This interferes with the normal routing because a named (secondary) outlet is not the same as a child outlet.AuthenticationModulegets loaded.