How to route to a Module as a child of a Module - Angular 2 RC 5

前端 未结 7 1248
暖寄归人
暖寄归人 2020-12-04 07:43

I am in the process upgrading an application I\'m working on to the latest Angular 2 release candidate. As part of this work I am attempting to use the NgModule spec and mig

7条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-04 07:57

    I think 2.0.0 rc5 isn't interested now. But is is worked in Angular 4, may be early too.

    @NgModule({
        imports: [
            RouterModule.forRoot([
                    {path: "", redirectTo: "test-sample", pathMatch: "full"},
                    {
                        path: "test-sample",
                        loadChildren: () => TestSampleModule
                    }
            ])
        ],
        exports: [RouterModule],
        declarations: [] 
    }) 
    export class AppRoutingModule{}
    
    @NgModule({
        imports: [
            RouterModule.forChild([{
                        path: "",
                        component: TestSampleComponent,
                        children: [
                            {path: "", redirectTo: "home", pathMatch: "full"},
                            {
                                path: "home",
                                loadChildren: () => HomeModule
                            },
                            {
                                path: "about",
                                loadChildren: () => AboutModule
                            }
                        ]
                    }
            ])
        ],
        exports: [RouterModule],
        declarations: []
    })
    export class TestSampleRoutingModule {}
    
    @NgModule({
        imports: [RouterModule.forChild([{
                        path: "",
                        component: AboutComponent
                    }
        ])],
        exports: [RouterModule]
    })
    export class AboutRoutingModule {}
    

    Take in account on loadChildren: () => {...}. It is not the lazy loading.

    See for details feat: Support NgModules hierarchy sans Lazy Loading

提交回复
热议问题