Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
673 views
in Technique[技术] by (71.8m points)

angular2 routing - Angular Component not eager loaded

I want to eager load a component MyComponent.

AppModule imports SharedModule and AppRoutingModule, SharedModule declares MyComponent, AppComponent is bootstrapped.

app-routing.module.ts

const routes: Routes = [
    { path: home/comp, component: MyComponent }
    { path: home, loadChildren: () => import('./mymodule/mymodule.module')
                                .then(x => x.MyModule)},
]
@NgModule({
  imports: [
    RouterModule.forRoot(routes)
]

MyComponent is also a childroute in MyModule:

@NgModule({
    imports: [
      SharedModule, 
      RouterModule.forChild([   
        {
          path: 'home/comp',
           component: MyComponent
        }
    ]
}

But MyComponent is not eager loaded. As I am also mixing with lazy loading certain modules, is it possible I am overwriting things? Official documentation is not too clear to me.

I have tried

adding:

data:{preload:true} 

to the paths declared in routermodule

used:

loadChildren: () => import('./mycomponent/mycomponent.cmpnt').then(x => x.MyComponent)

both in AppModule as in MyComponent it was not successful. What am I doing wrong? Thanks

question from:https://stackoverflow.com/questions/65649477/angular-component-not-eager-loaded

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...