2

I want to create nested lazy loading in 3 levels but my scenario only works for the 2 base level app.module.ts and pages.module.ts I want to create the same scenario for persons.module.ts from pages.module.ts

my app.module.ts define and routing module like this:

@NgModule({
  declarations: [AppComponent],
  imports: [
    AppRoutingModule,      
  ],
  exports: [AppComponent],
  bootstrap: [AppComponent],
  providers: [
    AppRouteGuard,
    { provide: APP_BASE_HREF, useValue: '/' },
  ],
})
export class AppModule {
}

and in my app-routing.module.ts I define these routes:

const routes: Routes = [
  {
    path: 'pages',
    loadChildren: () => import('./pages/pages.module').then(mod => mod.PagesModule),
    canActivate : [AppRouteGuard]
  },
  {
    path: 'login',
    component: LoginComponent,
  },
  { path: '', redirectTo: 'pages', pathMatch: 'full' },
  { path: '**', redirectTo: 'pages' },
];

const config: ExtraOptions = {
  useHash: true,
};

@NgModule({
  imports: [RouterModule.forRoot(routes, config)],
  exports: [RouterModule],
})
export class AppRoutingModule {
}

and in my pages.module.ts I define a pages-routing.module.ts that have these codes:

const routes: Routes = [
  {
    path: '',
    component: PagesComponent,
    children: [
      {
        path: 'dashboard',
        component: ECommerceComponent,
      },
      {
        path: 'persons',
        loadChildren: () => import('./persons/persons.module').then(mod => mod.PersonsModule)
      },
      {
        path: '',
        redirectTo: 'persons',
        pathMatch: 'full',
      },
      {
        path: '**',
        component: NotFoundComponent,
      }
    ]
  }];


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

everything is ok for these levels but when I define persons-routing.module.ts like this :

    const routes: Routes = [
  {
    path: '',
    children: [
      {
        path: 'account-likes',
        component: LikesComponent
      },
      {
        path: '',
        redirectTo: 'account-likes',
        pathMatch: 'full'
      }
    ]
  }
    ]


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

and my temlplate like this:

<div class="row ml-0">
  <div class="col-xs-12 col-sm-6 col-md-5 col-lg-2 p-0 person-sidebar">
    <nb-card size="small" class="mb-0">
           hello world
    </nb-card>
  </div>
  <div class="col-xs-12 col-sm-6 col-md-7 col-lg-10 pl-0">
    <router-outlet></router-outlet>
  </div>
</div>

my persons.component.html display nothing can you help me?

2
  • Any errors in browser's console? Commented Jul 18, 2019 at 6:18
  • @hrdkisback I don't get any error just not display anything in person.component.html Commented Jul 18, 2019 at 7:20

2 Answers 2

1

Check this Working Example this

Sign up to request clarification or add additional context in comments.

3 Comments

I add the same code for that example but I don't know where is my code have problem
do u still have problem
can you post you error log in console to ur questiion
0

In your example the issue is in the PersonRoutingModule as no component is defined in Routes arrays so need to update the component in PersonRoutingModule.ts

3 Comments

I add PersonComponent for path=' ' but already not display anything
I add PersonComponent for path=' ' but already not display anything
In module Component name is required

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.