1

I'm trying to implement new lazyloaded module to app component, but when I trying to add child routes for new module

it throws 'router-outlet' is not a known element:in lazy loaded module error .

İn child module i import and export RouterModule .

const routes: Routes = [
  {
    path: '',
    component: ProfileComponent,
    children: [
      {path: '', pathMatch: 'full', component: PostsComponent},
      {path: 'media', component: MediaComponent},
      {path: 'settings', component: SettingsComponent},
    ]
  }
];

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

and profile module (the module I trying to implement) I import the Profile

@NgModule({
  declarations: [PostsComponent, MediaComponent, SettingsComponent],
  imports: [
    CommonModule,
    SharedModule,
    ProfileRoutingModule
  ]
})
export class ProfileModule {
}

and part of AppRoutingModule

{
   path: 'profile',
   loadChildren: () => import('./profile/profile.module')
     .then(m => m.ProfileModule)
}

Other modules works pretty fine but when I try to lazy load module it gives me this error

Teoman Tıngır
  • 2,766
  • 2
  • 21
  • 41

1 Answers1

0

I'd guess that you forgot to export the RouterModule in your AppRoutingModule. Stackblitz to reproduce the error: https://stackblitz.com/edit/angular-jd3ehv?file=src%2Fapp%2Fapp-routing.module.ts

@NgModule({
  imports: [
    RouterModule.forRoot([
      {
        path: "recipe",
        loadChildren: () =>
          import("./recipe/recipe.module").then(mod => mod.RecipeModule)
      }
    ])
  ],
  exports: [RouterModule] // <==== add this line
})
export class AppRoutingModule {}

Kari F.
  • 1,214
  • 10
  • 16