2016-11-29 106 views
1

我必須開發一個角度2應用程序,它是其他角度2應用程序的包裝。Angular 2包裝項目

可以說,項目的主要模塊稱爲MainModule其部署在NPM 其他第三方模塊AppModule1,AppModule2,... 我可以將其與安裝到我的主要項目「NPM我appmodule1」等。

這裏是我的代碼:

import {AppModule1} from 'ThirdPartyLibrary/AppModule1'; 
import {AppModule2} from 'ThirdPartyLibrary/AppModule2'; 
import {AppModule3} from 'ThirdPartyLibrary/AppModule3'; 

(模塊的進口休息太) ..(可以說我做了這個動態)

@NgModule({ 
imports: [ 
    BrowserModule, 
    HttpModule, 
    FormsModule, 
    RouterModule.forRoot(routes), 
    AppModule1,AppModule2,..(lets say I made this dynamic) 
], 
declarations: [ 
    MainComponent 
], 
schemas: [ CUSTOM_ELEMENTS_SCHEMA ], 
providers: [ 
    AnyMainModuleService, 
    {provide: LocationStrategy, useClass: HashLocationStrategy} 
], 
bootstrap: [ MainComponent ] 

}) 出口類MainModule {}

AppModule1,2,3 ..具有進口陣列中其RouterModule.forChild(路由)。我也嘗試使用RouterModule.forRoot(路由)。

路由器配置:

{ path: '', redirectTo: 'AppComponent1' }, 
{ path: 'appcomponent1', component: AppComponent1 }, 
{ path: 'appcomponent2', component: AppComponent2 }, 
{ path: 'appcomponent3', component: AppComponent3 }, 
{ path: 'appcomponent4', component: AppComponent4, children: childRoutesOfAppModule4enter code here }, 

內部AppModule4路由器配置

export const routes: Routes = [ 
     { path: '', redirectTo: 'home'}, 
     { path: 'home', component: HomeComponent }, 
     { path: 'about', component: AboutComponent} 
    ]; 

的問題是,其被認爲是主要組件的子路由AppModule4的路由器配置過騎着主路由器。

只要我進入本地主機我有看到AppComponent1但我得到HomeComponent。

回答

0
{ path: 'appcomponent4', component: AppComponent4, loadChildren:() => AppModule4} 

使用這種導入路由器模塊和AppModule4內安裝路徑爲RouterModule.forChild(路由)