首页 文章

Angular 2包装器项目

提问于
浏览
1

我必须开发一个角度2应用程序,它是其他角度2应用程序的包装器 .

让我们说项目的主要模块叫做MainModule在npm中部署的其他第三方模块是AppModule1,AppModule2,......我可以使用'npm i 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 ..在imports数组中有RouterModule.forChild(routes) . 我也尝试过使用RouterModule.forRoot(路由) .

Router configuration:

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

Router config inside AppModule4

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

问题是AppModule4的路由器配置应该是主要组件的子路由,它超越了主路由器 .

一进入localhost,我就会看到AppComponent1,但我得到HomeComponent .

1 回答

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

    使用它来导入路由器模块和AppModule4安装路由内部作为RouterModule.forChild(路由)

相关问题