简体   繁体   English

Angular 2 +延迟加载模块被导入的模块覆盖

[英]Angular 2 + Lazyloaded Module is being overridden by an imported module

I would like to know how to import a module without it taking priority over the parent module. 我想知道如何导入一个模块而不使其优先于父模块。 I am trying to understand why my imported module is overriding the parent modules entry component. 我试图了解为什么我的导入模块覆盖了父模块入口组件。 I import the QuotesModule into my CompaniesModule so that it's components are available to my CompaniesModule . 我导入QuotesModule到我CompaniesModule使得它的组件提供给我CompaniesModule When the QuotesModule is imported as shown here: 导入QuotesModule ,如下所示:

CompaniesModule (lazyloaded)

const ROUTES: Routes = [
    {path: '', component: CompaniesComponent}
];

@NgModule({
    declarations: [
        CreateCompanyComponent,
        CompaniesComponent
    ],
    providers: [
    ],
    imports: [
        QuotesModule,
        FormsModule,
        ReactiveFormsModule,
        GlobalModule,
        CommonModule,
        RouterModule.forChild(ROUTES)
    ],
    exports: [
    ],
    schemas: [
        CUSTOM_ELEMENTS_SCHEMA
    ],
    entryComponents: [
        CompaniesComponent
    ]

})

...and I attempt to navigate to CompaniesComponent route, the QuotesModule entry component resolves instead. ...并且我尝试导航到CompaniesComponent路线, QuotesModule条目组件解析。 Any insight would be much appreciated! 任何见解将不胜感激!

Here is my QuotesModule Routes and NgModule: 这是我的QuotesModule路由和NgModule:

const ROUTES: Routes = [
    {path: '', component: QuotesComponent}
];

@NgModule({
    declarations: [
        QuotesComponent
    ],
    providers: [
    ],
    imports: [
        CommonModule,
        GlobalModule,
        RouterModule.forChild(ROUTES)
    ],
    exports: [
    ]

})

I will post as answer then (based on above comments)... 然后我将作为答案发布(基于以上评论)...

...the problem sounds like your router, not the lazy loaded modules (depending on if those modules are in fact loading correctly). ...问题听起来像是您的路由器,而不是延迟加载的模块(取决于这些模块实际上是否正确加载)。 Check that the child routes vs. main routes aren't overwriting each other. 检查子路由与主路由之间是否相互覆盖。

And glad to have helped. 很高兴为您提供帮助。 Tracking down router issues can be a bear. 追踪路由器问题可能会很麻烦。

The problem was the routing. 问题是路由。 I had used different paths to lazy load my QuotesModule independently of the CompanyModule and when imported, QuotesModule 's routes matched and then overwrote the importing modules routes. 我已经使用不同的路径延迟加载我QuotesModule独立的CompanyModule和进口时, QuotesModule的路线匹配,然后覆盖了导入模块的路由。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM