Repository navigation
Description
Hi :)
I lately refactor my project to work with lazy loaded module and webpack bundling for better performance.
so first of all this is crazy how fast my app become on bootstrap! :)
but the only thing that is kind of frustrating is that when I define a routes for for lazy loaded module that contains a children is it kind of tricky, because the way that I need to define the children when I only use it for debugging (without bundling) is different from the way I need to define it with bundling, and I will give an example:
without bundling - the relative path for the children module is relative to the app folder:
export const routes = [
{
path: '',
component: ParentComponent,
children: [
{
path: 'secondChilldren',
loadChildren: "./pages/secondChilldren/secondChilldren/secondChilldren.module#SecondChilldrenModule",
},
{
path: 'firstChildren',
loadChildren: "./pages/firstChildren/firstChildren/firstChildren.module#FirstChildrenModule",
},
{ path: '', redirectTo: 'firstChildren', pathMatch: 'full' },
]
}
];
With bundling - the relative path for the children module is relative to the parentComponent folder:
export const routes = [
{
path: '',
component: ParentComponent,
children: [
{
path: 'secondChilldren',
loadChildren: "../secondChilldren/secondChilldren/secondChilldren.module#SecondChilldrenModule",
},
{
path: 'firstChildren',
loadChildren: "../firstChildren/firstChildren/firstChildren.module#FirstChildrenModule",
},
{ path: '', redirectTo: 'firstChildren', pathMatch: 'full' },
]
}
];
little update:
The issue is all about the relative path of nested lazy loading component, cause I checked it and when set the route of the children not to be lazy loaded and set it with the actual component ( like this: component: firstChildrenComponent instead of loadChildren: "../firstChildren/firstChildren/firstChildren.module#FirstChildrenModule" ), it works.
but still it would be great to figure it out how to do it with nested lazy loading. :)
Thank you! :)
Activity
NickIliev commentedon Feb 13, 2018
@shabib3 glad to hear you have achieved such great performance boost!
Regarding your issue with the relative and absolute paths of the lazily loaded modules (with or without Webpack) - I can confirm that this is indeed a real issue logged here.
We are currently working on it and will post any additional info in the linked issue - meanwhile continue using the workaround you have found.
bzaruk commentedon Feb 13, 2018
@NickIliev
Just to add another thing - my
little updatethat I wrote not really works for both situation (regular and bundling)...it iד actually the same situation that works only for bundling.so for this situation, the workaround is to change the relative path when running with bundling :)
FrontEnd-Miracle-1 commentedon Aug 19, 2018
@shabib3 - When you say "so for this situation, the workaround is to change the relative path when running with bundling", do you mean that you simply don't use Lazy Loading together with Webpack in your project?
I am asking because I have the apparently unanswerable error "No module factory available for dependency type: ContextElementDependency at Compilation". And it is caused by the "loadChildren" with the relative path of nested lazy loading...