1
votes

I am trying to use lazy loaded module routes as shown below but it cannot find a match for the URL localhost:4200/authorization/opcodes. It can load the main page though.

src\app\app-routing.module.ts

const routes: Routes = [
{
    path: '',
    loadChildren: './modules/main-page/main-page.module#MainPageModule'
},
{
    path: 'feature',
    loadChildren: './modules/feature/feature.module#FeatureModule'
}

];

src\app\modules\main-page\main-page-routing.module.ts

const routes: Routes = [
{
    path: '',
    component: MainPageComponent,
    canActivate: [AuthGuard],
    children:[
        {
           path: 'authorization',
           loadChildren: './authorization/authorization.module#AuthorizationModule'
         }
      ]
    }
];

src\app\modules\main-page\authorization\authorization-routing.module.ts

const routes: Routes = [
{
    path: 'opcodes',
    component: OpCodeComponent
}
];

@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})

MainPageComponent is the main layout that includes a router-outlet that will host the OpCodesComponent.

So the router flow should be: AppRouterModule --> MainPageRouterModule --> AuthorizationRouterModule.

1
The main page, which looks like its the first page of your app is lazy loaded? this doesn't make sense - benshabatnoam
@benshabatnoam Well the app component only includes a router and depending on the logged in status of the user, navigation either loads the authentication module (which I renamed as feature module above in order to prevent confusion between authentication and authorization) or the authorization module, which is another feature module. - hakanviv

1 Answers

0
votes

I found the problem. Apparently, I had forgotten to import AuthorizationRoutingModule into AuthorizationModule. And the framework has given no warning implying this. It would have been helpful if Angular explicitly warned about this.