2017-10-14 32 views
0

在Angular4中,您可以在pathToMyModule#MyModule的路由配置中使用loadChrildren屬性來延遲加載模塊。我想知道是否有任何屬性,我可以指定總是加載我的模塊(所以基本上禁用延遲加載)。Angular4如何以熱切的方式加載模塊

+0

讀這篇文章[避免常見的混亂與角模塊(https://blog.angularindepth.com/avoiding-common-confusions-with-modules-in-angular-ada070e6891f) –

回答

1

導入啓動應用程序時引導的模塊中的所有模塊。通常它被稱爲AppModule。這是默認的方式。那麼請不要使用loadChrildren。這些模塊應該分層次導入,然後所有的模塊將被熱切導入。

@NgModule({ 
    imports: [ 
     AppRoutingModule, 
     LoginModule, 
     //here you should import all other modules, or other the modules should import each other hierarchically 
    ], 
    declarations: [ 
     AppComponent  
    ], 
    bootstrap: [AppComponent] 
}) 

export class AppModule { 

} 

@NgModule({ 
    imports: [ 
     RouterModule.forRoot([ 
     {path: '', component: SomeComponent}  
    ], 
    exports: [ 
     RouterModule 
    ] 
}) 
export class AppRoutingModule { 
} 




@NgModule({ 
    imports: [ 
     LoginRoutingModule 
    ] 
}) 
export class LoginModule { 
} 


@NgModule({ 
    imports: [ 
    RouterModule.forChild([ 
     { 
     path: 'login', 
     children: [ 
      {path: '', pathMatch: 'full', redirectTo: 'somepath'}, 
      {path: 'somepath', component: SomeOtherComponent}, 
     ] 
     } 

    ]) 
    ], 
    exports: [ 
    RouterModule 
    ] 
}) 
export class LoginRoutingModule { 
} 
+0

所以沒有其他方式,然後結束了一個單一的路線文件? – Scipion

+0

@Scipion我編輯了答案 – omeralper