Angular: Eager loading makes component to not be rendered












0















I want to have the following structure in DOM:



<myapp-root>
<router-outlet></router-outlet>

<myapp-user-management>
<router-outlet></router-outlet>
<myapp-users></myapp-users>
</myapp-user-management>

</myapp-root>


(1) I made a lazy loading for UserManagementModule in root-routing.module.ts like so



const rootRoutes: Routes = [
{
...
children: [
...
{
path: 'userManagement',
loadChildren: '../user-management/user-management.module#UserManagementModule'
},
...
]
}
];

@NgModule({
imports: [
RouterModule.forChild(rootRoutes)
],
exports: [RouterModule]
})
export class RootRoutingModule {
}


and then I imported the routing module in RootModule



@NgModule({
...
imports: [
...
RootRoutingModule,
...
]
})
export class RootModule {
}


The root.component.html has a <router-outlet></router-outlet>



(2) After that I wanted to make an eager load of UsersModule. So I in user-management-routing.module.ts I have



const userManagementRoutes: Routes = [
{
path: '',
component: UserManagementComponent
}
];


@NgModule({
declarations: ,
imports: [
RouterModule.forChild(userManagementRoutes)
],
exports: [RouterModule]
})
export class UserManagementRoutingModule { }


and in user-management.module.ts I have



@NgModule({
imports: [
UsersModule,
UserManagementRoutingModule
]
})
export class UserManagementModule { }


The user-management.component.html has a <router-outlet></router-outlet>



(3) Then I written the users-routing.module.ts as follows



const usersRoutes: Routes = [
{
path: 'users',
component: UsersComponent
}
];

@NgModule({
declarations: ,
imports: [
RouterModule.forChild(usersRoutes)
],
exports: [RouterModule]
})
export class UsersRoutingModule {
}


and the users.module.ts as follows



@NgModule({
declarations: [
UsersComponent
],
imports: [
CommonModule,
UsersRoutingModule,
],
exports: [
]
})
export class UsersModule { }


The problem is it renders



<myapp-root>
<router-outlet></router-outlet>
<myapp-users></myapp-users>
</myapp-root>


What I am doing wrong?










share|improve this question























  • The users route must be a child route of the unique, empty-path route in userManagementRoutes.

    – JB Nizet
    Nov 26 '18 at 10:40











  • Besides @JBNizet comment, you can still import UsersModule within UserManagementModule to bundle them together but as he stated, users route should be defined within userManagementRoutes as if you are defining a lazy loaded module.

    – Bunyamin Coskuner
    Nov 26 '18 at 10:43











  • @JBNizet and @Bunyamin Coskuner Yeah, but this is not a modular approach. I want to have all the user routes in the user-routing.module.ts. Suppose, in the future, I will add another module, say user-groups module. Then I don't want to crowd the countries routes in user-management routes. I want them to be separate

    – MTZ
    Nov 26 '18 at 11:13













  • Not everything needs to be an Angular module. You can simple export a const defining the users routes, and use children: USERS_ROUTES.

    – JB Nizet
    Nov 26 '18 at 11:14













  • @JBNizet I know, but maybe tomorrow the client will tell me to move the Users section in another place. Then I want to make this thing quick. This is the reason for which I want to make a Users Module

    – MTZ
    Nov 26 '18 at 11:16
















0















I want to have the following structure in DOM:



<myapp-root>
<router-outlet></router-outlet>

<myapp-user-management>
<router-outlet></router-outlet>
<myapp-users></myapp-users>
</myapp-user-management>

</myapp-root>


(1) I made a lazy loading for UserManagementModule in root-routing.module.ts like so



const rootRoutes: Routes = [
{
...
children: [
...
{
path: 'userManagement',
loadChildren: '../user-management/user-management.module#UserManagementModule'
},
...
]
}
];

@NgModule({
imports: [
RouterModule.forChild(rootRoutes)
],
exports: [RouterModule]
})
export class RootRoutingModule {
}


and then I imported the routing module in RootModule



@NgModule({
...
imports: [
...
RootRoutingModule,
...
]
})
export class RootModule {
}


The root.component.html has a <router-outlet></router-outlet>



(2) After that I wanted to make an eager load of UsersModule. So I in user-management-routing.module.ts I have



const userManagementRoutes: Routes = [
{
path: '',
component: UserManagementComponent
}
];


@NgModule({
declarations: ,
imports: [
RouterModule.forChild(userManagementRoutes)
],
exports: [RouterModule]
})
export class UserManagementRoutingModule { }


and in user-management.module.ts I have



@NgModule({
imports: [
UsersModule,
UserManagementRoutingModule
]
})
export class UserManagementModule { }


The user-management.component.html has a <router-outlet></router-outlet>



(3) Then I written the users-routing.module.ts as follows



const usersRoutes: Routes = [
{
path: 'users',
component: UsersComponent
}
];

@NgModule({
declarations: ,
imports: [
RouterModule.forChild(usersRoutes)
],
exports: [RouterModule]
})
export class UsersRoutingModule {
}


and the users.module.ts as follows



@NgModule({
declarations: [
UsersComponent
],
imports: [
CommonModule,
UsersRoutingModule,
],
exports: [
]
})
export class UsersModule { }


The problem is it renders



<myapp-root>
<router-outlet></router-outlet>
<myapp-users></myapp-users>
</myapp-root>


What I am doing wrong?










share|improve this question























  • The users route must be a child route of the unique, empty-path route in userManagementRoutes.

    – JB Nizet
    Nov 26 '18 at 10:40











  • Besides @JBNizet comment, you can still import UsersModule within UserManagementModule to bundle them together but as he stated, users route should be defined within userManagementRoutes as if you are defining a lazy loaded module.

    – Bunyamin Coskuner
    Nov 26 '18 at 10:43











  • @JBNizet and @Bunyamin Coskuner Yeah, but this is not a modular approach. I want to have all the user routes in the user-routing.module.ts. Suppose, in the future, I will add another module, say user-groups module. Then I don't want to crowd the countries routes in user-management routes. I want them to be separate

    – MTZ
    Nov 26 '18 at 11:13













  • Not everything needs to be an Angular module. You can simple export a const defining the users routes, and use children: USERS_ROUTES.

    – JB Nizet
    Nov 26 '18 at 11:14













  • @JBNizet I know, but maybe tomorrow the client will tell me to move the Users section in another place. Then I want to make this thing quick. This is the reason for which I want to make a Users Module

    – MTZ
    Nov 26 '18 at 11:16














0












0








0








I want to have the following structure in DOM:



<myapp-root>
<router-outlet></router-outlet>

<myapp-user-management>
<router-outlet></router-outlet>
<myapp-users></myapp-users>
</myapp-user-management>

</myapp-root>


(1) I made a lazy loading for UserManagementModule in root-routing.module.ts like so



const rootRoutes: Routes = [
{
...
children: [
...
{
path: 'userManagement',
loadChildren: '../user-management/user-management.module#UserManagementModule'
},
...
]
}
];

@NgModule({
imports: [
RouterModule.forChild(rootRoutes)
],
exports: [RouterModule]
})
export class RootRoutingModule {
}


and then I imported the routing module in RootModule



@NgModule({
...
imports: [
...
RootRoutingModule,
...
]
})
export class RootModule {
}


The root.component.html has a <router-outlet></router-outlet>



(2) After that I wanted to make an eager load of UsersModule. So I in user-management-routing.module.ts I have



const userManagementRoutes: Routes = [
{
path: '',
component: UserManagementComponent
}
];


@NgModule({
declarations: ,
imports: [
RouterModule.forChild(userManagementRoutes)
],
exports: [RouterModule]
})
export class UserManagementRoutingModule { }


and in user-management.module.ts I have



@NgModule({
imports: [
UsersModule,
UserManagementRoutingModule
]
})
export class UserManagementModule { }


The user-management.component.html has a <router-outlet></router-outlet>



(3) Then I written the users-routing.module.ts as follows



const usersRoutes: Routes = [
{
path: 'users',
component: UsersComponent
}
];

@NgModule({
declarations: ,
imports: [
RouterModule.forChild(usersRoutes)
],
exports: [RouterModule]
})
export class UsersRoutingModule {
}


and the users.module.ts as follows



@NgModule({
declarations: [
UsersComponent
],
imports: [
CommonModule,
UsersRoutingModule,
],
exports: [
]
})
export class UsersModule { }


The problem is it renders



<myapp-root>
<router-outlet></router-outlet>
<myapp-users></myapp-users>
</myapp-root>


What I am doing wrong?










share|improve this question














I want to have the following structure in DOM:



<myapp-root>
<router-outlet></router-outlet>

<myapp-user-management>
<router-outlet></router-outlet>
<myapp-users></myapp-users>
</myapp-user-management>

</myapp-root>


(1) I made a lazy loading for UserManagementModule in root-routing.module.ts like so



const rootRoutes: Routes = [
{
...
children: [
...
{
path: 'userManagement',
loadChildren: '../user-management/user-management.module#UserManagementModule'
},
...
]
}
];

@NgModule({
imports: [
RouterModule.forChild(rootRoutes)
],
exports: [RouterModule]
})
export class RootRoutingModule {
}


and then I imported the routing module in RootModule



@NgModule({
...
imports: [
...
RootRoutingModule,
...
]
})
export class RootModule {
}


The root.component.html has a <router-outlet></router-outlet>



(2) After that I wanted to make an eager load of UsersModule. So I in user-management-routing.module.ts I have



const userManagementRoutes: Routes = [
{
path: '',
component: UserManagementComponent
}
];


@NgModule({
declarations: ,
imports: [
RouterModule.forChild(userManagementRoutes)
],
exports: [RouterModule]
})
export class UserManagementRoutingModule { }


and in user-management.module.ts I have



@NgModule({
imports: [
UsersModule,
UserManagementRoutingModule
]
})
export class UserManagementModule { }


The user-management.component.html has a <router-outlet></router-outlet>



(3) Then I written the users-routing.module.ts as follows



const usersRoutes: Routes = [
{
path: 'users',
component: UsersComponent
}
];

@NgModule({
declarations: ,
imports: [
RouterModule.forChild(usersRoutes)
],
exports: [RouterModule]
})
export class UsersRoutingModule {
}


and the users.module.ts as follows



@NgModule({
declarations: [
UsersComponent
],
imports: [
CommonModule,
UsersRoutingModule,
],
exports: [
]
})
export class UsersModule { }


The problem is it renders



<myapp-root>
<router-outlet></router-outlet>
<myapp-users></myapp-users>
</myapp-root>


What I am doing wrong?







angular






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 26 '18 at 10:24









MTZMTZ

8614




8614













  • The users route must be a child route of the unique, empty-path route in userManagementRoutes.

    – JB Nizet
    Nov 26 '18 at 10:40











  • Besides @JBNizet comment, you can still import UsersModule within UserManagementModule to bundle them together but as he stated, users route should be defined within userManagementRoutes as if you are defining a lazy loaded module.

    – Bunyamin Coskuner
    Nov 26 '18 at 10:43











  • @JBNizet and @Bunyamin Coskuner Yeah, but this is not a modular approach. I want to have all the user routes in the user-routing.module.ts. Suppose, in the future, I will add another module, say user-groups module. Then I don't want to crowd the countries routes in user-management routes. I want them to be separate

    – MTZ
    Nov 26 '18 at 11:13













  • Not everything needs to be an Angular module. You can simple export a const defining the users routes, and use children: USERS_ROUTES.

    – JB Nizet
    Nov 26 '18 at 11:14













  • @JBNizet I know, but maybe tomorrow the client will tell me to move the Users section in another place. Then I want to make this thing quick. This is the reason for which I want to make a Users Module

    – MTZ
    Nov 26 '18 at 11:16



















  • The users route must be a child route of the unique, empty-path route in userManagementRoutes.

    – JB Nizet
    Nov 26 '18 at 10:40











  • Besides @JBNizet comment, you can still import UsersModule within UserManagementModule to bundle them together but as he stated, users route should be defined within userManagementRoutes as if you are defining a lazy loaded module.

    – Bunyamin Coskuner
    Nov 26 '18 at 10:43











  • @JBNizet and @Bunyamin Coskuner Yeah, but this is not a modular approach. I want to have all the user routes in the user-routing.module.ts. Suppose, in the future, I will add another module, say user-groups module. Then I don't want to crowd the countries routes in user-management routes. I want them to be separate

    – MTZ
    Nov 26 '18 at 11:13













  • Not everything needs to be an Angular module. You can simple export a const defining the users routes, and use children: USERS_ROUTES.

    – JB Nizet
    Nov 26 '18 at 11:14













  • @JBNizet I know, but maybe tomorrow the client will tell me to move the Users section in another place. Then I want to make this thing quick. This is the reason for which I want to make a Users Module

    – MTZ
    Nov 26 '18 at 11:16

















The users route must be a child route of the unique, empty-path route in userManagementRoutes.

– JB Nizet
Nov 26 '18 at 10:40





The users route must be a child route of the unique, empty-path route in userManagementRoutes.

– JB Nizet
Nov 26 '18 at 10:40













Besides @JBNizet comment, you can still import UsersModule within UserManagementModule to bundle them together but as he stated, users route should be defined within userManagementRoutes as if you are defining a lazy loaded module.

– Bunyamin Coskuner
Nov 26 '18 at 10:43





Besides @JBNizet comment, you can still import UsersModule within UserManagementModule to bundle them together but as he stated, users route should be defined within userManagementRoutes as if you are defining a lazy loaded module.

– Bunyamin Coskuner
Nov 26 '18 at 10:43













@JBNizet and @Bunyamin Coskuner Yeah, but this is not a modular approach. I want to have all the user routes in the user-routing.module.ts. Suppose, in the future, I will add another module, say user-groups module. Then I don't want to crowd the countries routes in user-management routes. I want them to be separate

– MTZ
Nov 26 '18 at 11:13







@JBNizet and @Bunyamin Coskuner Yeah, but this is not a modular approach. I want to have all the user routes in the user-routing.module.ts. Suppose, in the future, I will add another module, say user-groups module. Then I don't want to crowd the countries routes in user-management routes. I want them to be separate

– MTZ
Nov 26 '18 at 11:13















Not everything needs to be an Angular module. You can simple export a const defining the users routes, and use children: USERS_ROUTES.

– JB Nizet
Nov 26 '18 at 11:14







Not everything needs to be an Angular module. You can simple export a const defining the users routes, and use children: USERS_ROUTES.

– JB Nizet
Nov 26 '18 at 11:14















@JBNizet I know, but maybe tomorrow the client will tell me to move the Users section in another place. Then I want to make this thing quick. This is the reason for which I want to make a Users Module

– MTZ
Nov 26 '18 at 11:16





@JBNizet I know, but maybe tomorrow the client will tell me to move the Users section in another place. Then I want to make this thing quick. This is the reason for which I want to make a Users Module

– MTZ
Nov 26 '18 at 11:16












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53479076%2fangular-eager-loading-makes-component-to-not-be-rendered%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53479076%2fangular-eager-loading-makes-component-to-not-be-rendered%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Ottavio Pratesi

Tricia Helfer

15 giugno