The database stores the URL, which should load the module from the directory 'dist'.
{
"personal-area": "js/compile-module.js",
"product": "js/compile-module2.js"
}
Application example:
http://localhost:8282/#/personal-area
Then the application lazy (async|dynamic|any) loads the module from:
http://localhost:8282/js/compile-module.js
Modules are precompiled in advance and at the stage of building the main application they do not participate, so I do not have any paths to the sources of angular modules.
In the file with routing (app.routers.ts) I store the component handler, which pulls from the database the path to the module file on the server (based on URL).
export const ROUTES: Routes = [
{
path: '**',
component: WorkspaceOutletComponent
},
];
In the main handler there is a method that tries to load the module, but for reasons I do not understand, I do not know how to make Angular connect the compiled module for the eagle and work.
@Component({ ... })
export class WorkspaceOutletComponent {
constructor() {
}
ngOnInit() {
// detect routing and exec init
}
public init(workSpaceUrl: string, workSpacePathModule: string) {
console.log(`url: ${workSpaceUrl} path: ${workSpacePathModule}`);
this.router.resetConfig([
{
path: workSpaceUrl, loadChildren: workSpacePathModule
}
]);
this.router.navigate([workSpaceUrl])
.then(() => console.log('Navigate to'))
.catch((e) => console.error('Error', e));
}
}
The application is built using webpack 2. But at the moment when I replace routing, he writes me a mistake, and I do not even know where to dig to dynamically load the module (which I need to come from the database), I do not know the reference to the module during the assembly, nothing, I do not even have source codes, So I need third-party modules to load into runtime. What am I doing wrong?
If I use SystemJS. It also does not help, it tries to load the module from the disk (from source).
this.router.resetConfig([
{
path: workSpaceUrl, loadChildren: SystemJS.import(workSpacePathModule).then(function (m) {
console.log(m);
})
}
]);
Here a little is told about how the loading of modules works: https://github.com/angular/angular-cli/issues/4234#issuecomment-275345763
Do I understand correctly that Angular needs an exact name so that he compiles a hash map. And that's why you can not pass it as I do it, but what should I do if I do not know the correspondence between the path on the disk (since I do not have source codes)?

