Angular 9 Dynamically import modules with dynamic routes

Ömrüm Baki

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:

 project structure

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 :)

Error

DMITRYTISHKIN

Unfortunately, using dynamic string for dynamic imports is impossible

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related