0

I know that we can use lazy loading by specifying path to module:

const routes: Routes = [
    {path: '', component: AdminComponent, children: [
        {path: 'app', loadChildren: './app/app.module#AppModule' },
        {path: 'anotherPath', component: SomeComponent }
    ]},
];

Is there possibility to define lazyloaded module as?:

import {AppModule} from 'somePath';
const routes: Routes = [
    {path: '', component: AdminComponent, children: [
        {path: 'app', loadChildren: AppModule },
        {path: 'anotherPath', component: SomeComponent }
    ]},
];

The reason why I am asking about that is:

I want to keep my child modules in different git repos, and install them as dependencies of main project. Thats requires from me to specify path to module as follows:

{path: 'moduleA', loadChildren: '../node_modules/my-module-A/some_other_path/app/app.module#AppModule' },

This already looks a little bit weird for me.

Now imagine situation, that moduleA have another dependency, let's say moduleAB. So here, again developer is specifieng path to module as ../node_modules/etc

When we isntall moduleA in our main application, we got following catalog structure:

- application_code/
|
- node_modules/
     |
      - moduleA/
     |     |
     |      - src/module_code_goes_here
     |
      - moduleAB/
          |
           - src/module_code_goes_here

And now the problem starts. ModuleA is loaded properly, but for ModuleAB angular is trying to look for in catalog node_modules/moduleA/node_modules/moduleAB instead of node_modules/moduleAB.

So if you want to develop big app, built from seperated modules which could depend on other modules, big disaster is coming...

Maciej Treder
  • 11,866
  • 5
  • 51
  • 74
  • 1
    Have you checked: http://stackoverflow.com/questions/40293240/how-to-manually-lazy-load-a-module – eko Apr 05 '17 at 08:35
  • Yup. But this is not answering my question. I don't want to load module manually. I wan't to specify path by import rather then string with path to node_modules catalog – Maciej Treder Apr 09 '17 at 13:14

0 Answers0