The database stores the URL that should load the module from the 'dist' directory.
{
"personal-area": "js/compile-module.js",
"product": "js/compile-module2.js"
}
For example, when using the application:
http://localhost:8282/#/personal-area
The application then lazy loads the module from:
http://localhost:8282/js/compile-module.js
The modules are precompiled in advance and are not involved during the main application building stage, which means there are no paths to the sources of Angular modules.
In the routing file (app.routers.ts), the component handler stores the server path to the module file based on the URL pulled from the database.
export const ROUTES: Routes = [
{
path: '**',
component: WorkspaceOutletComponent
},
];
In the main handler, there is a method trying to load the module dynamically for the application to function properly.
@Component({ ... })
export class WorkspaceOutletComponent {
constructor() {
}
ngOnInit() {
// detect routing and execute initialization
}
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. However, when trying to replace routing, an error occurs indicating difficulty dynamically loading the required module from the database without source codes available.
If SystemJS is used, it also encounters issues while attempting to load the module from the disk instead of the source.
this.router.resetConfig([
{
path: workSpaceUrl, loadChildren: SystemJS.import(workSpacePathModule).then(function(m) {
console.log(m);
})
}
]);
More information about how module loading works can be found at: https://github.com/angular/angular-cli/issues/4234#issuecomment-275345763
Could it be that Angular requires an exact name to compile a hash map, thus causing issues in passing the necessary parameters if the source code is unavailable?