Angular 2 lazy-loading modules from within a lazy-loaded module

Discussão em 'Angular' iniciado por BugsyFTW, Dezembro 8, 2024.

  1. BugsyFTW

    BugsyFTW Guest

    I'm developing a simple web page which has a Home Module which contains two components, Homepage and Login which I load using Lazy-Loading...

    This is my App-Routing Module

    const routes: Routes = [
    { path: '', redirectTo: 'home', pathMatch: 'full' },
    { path: 'home', loadChildren: 'app/home/home.module#HomeModule' },
    { path: 'main', loadChildren: 'app/main/main.module#MainModule' }
    ];

    @NgModule({
    imports: [
    HomeRoutingModule,
    RouterModule.forRoot(routes)
    ],
    exports: [RouterModule],
    providers: []
    })
    export class GESFWRoutingModule { }


    This is my Home Module...

    const routes = [
    { path: 'home', component: HomeComponent },
    { path: 'login', component: LoginComponent }
    ]

    @NgModule({
    imports: [
    CommonModule,
    RouterModule.forChild(routes),
    ReactiveFormsModule
    ],
    declarations: [
    HomeComponent,
    LoginComponent
    ],
    providers: [
    AuthService
    ]
    })
    export class HomeModule { }


    This part is working just fine, as expected. What I'm having a problem is when I go to the Main Module... I'm trying to lazy-load my client module

    const routes: Routes = [
    { path: '', redirectTo: 'main', pathMatch: 'full', children: [
    { path: 'clientes', loadChildren: 'app/clientes/clientes.module#ClientesModule' }
    ]},
    ];

    @NgModule({
    imports: [
    CommonModule,
    MainRoutingModule,
    RouterModule.forChild(routes)
    ],
    declarations: [
    MainComponent,
    HeaderComponent,
    ],
    })
    export class MainModule { }


    With the Client Module here...

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

    @NgModule({
    imports: [
    CommonModule,
    RouterModule.forChild(routes)
    ],
    declarations: [
    ClientesComponent,
    ClientesOperacoesComponent,
    SearchTableComponent
    ],
    providers: [
    MainService
    ]
    })
    export class ClientesModule { }


    Everything works until I try to access '/main/clientes'. It says that it cannot match any routes : 'main/clientes'. Now I've tried multiple ways to solve this, but always this the same problem, if you can find any error in my logic I would really appreciate it.

    Thanks!

    Continue reading...

Compartilhe esta Página