0
votes

I have a github project which would explain the issue

Get Project Here

const routes: Routes = [
  {
    path: 'admin',
    loadChildren: './admin/admin.module#AdminModule'
  },
  {
    path: '',
    component: HomeComponent
  }
];

this is from admin module routing

const routes: Routes = [{
  path: '',
  component: OverviewComponent
},
  {
    path: 'users',
    component: UserComponent
  }];

This project has home component with no paths in url

I see url paths are working even there is no module prefix.

Thanks in advance.

2
This would happen if you include your AdminModule in your AppModule. Make sure that your AdminModule is not imported anywhere. - tom van green

2 Answers

0
votes

In AdminModule, you should one also in admin.component.html.

You need to create AdminComponent as well for this.

For reference : https://www.tektutorialshub.com/angular-child-routes-nested-routes/

0
votes

It is because you have imported and declared admin components in app module itself. If you want lazy loading change app.module.ts file as below

@NgModule({
  declarations: [
    AppComponent,
    HomeComponent

  ],
  imports: [
    BrowserModule,
    AppRoutingModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

and admin.module.ts as below

@NgModule({
  imports: [
    CommonModule,
    AdminRoutingModule
  ],
  declarations: [OverviewComponent, UserComponent]
})
export class AdminModule { }