2

I have an Angular 5 project. Is this possible to do the next structure?

/app
 /folder1
  /comp1
  /comp2
  folder1.module.ts
 /folder2
  /comp1
  /comp2
  folder2.module.ts
app-routing.ts
...
...

So, my angular project knows nothing about this folders (folder1, folder2, etc) and I need to include them to app-routing dynamically by parameter value from url.

For example. Url: localhost:1111/folder1

and in app-routing.ts I want to have something like

const appRoutes: Routes = [
  {
    path: ':folderName',
    loadChildren: () => {
      var module = './{:folderName}.module';
      return import(module).then((comp: any) => {
        return comp.default;
      });
    }
  },

  {
    path: '',
    component: BaseComponent
  }
];

Is this possible or maybe any other options?

Thanks

Trick
  • 21
  • 1
  • check this out: https://stackoverflow.com/questions/40039825/angular2-loading-modules-dynamically-from-a-given-folder – Hussein Jun 16 '18 at 04:22
  • also i think lazy loading fits here: https://angular-2-training-book.rangle.io/handout/modules/lazy-loading-module.html – Hussein Jun 16 '18 at 05:40
  • Thanks. But the main problem, that I don't know how to work with a module from the variable. Each time I get an error that module "." is undefined. – Trick Jun 17 '18 at 22:19

0 Answers0