问题
I want to import angular modules dynamically with variable string routes from backend service. For example my backend service sends to me this response when app is starting(using APP_INITIALIZER).
{
"hostname": "a-tenant",
"modules": {
"home": {
"class": "HomeAModule",
"path": "home-a.module",
},
},
},
My app structure is:
So i want to import a module like this
const path = `./tenants/${response.hostname}/home/${response.modules.home.path}`;
import(path).then(m => m[response.modules.home.class]);
My final import code should be like this in runtime:
import('./tenants/a-tenant/home/home-a.module').then(m => m.HomeAModule);
But i'm getting this error, i think webpack does not handle dynamic loads like this.
Thank you for your help :)
回答1:
Unfortunately, using dynamic string for dynamic imports is impossible
来源:https://stackoverflow.com/questions/62011462/angular-9-dynamically-import-modules-with-dynamic-routes