shlomiassaf / ng-router-loader

Webpack loader for NgModule lazy loading using the angular router
MIT License
46 stars 8 forks source link

Relative path breaks with AoT #2

Closed glendaviesnz closed 7 years ago

glendaviesnz commented 7 years ago

Hi

For starters - thanks for your work on this module!

I have it all up and running fine, but with a '../+dashboard#DashBoard' type relative path in the loadChildren it works fine in dev server and standard build, but with AoT build I get:

ERROR in ./compiled/src/app/app.module.ngfactory.ts Module build failed: Error: Can't resolve '../+dashboard'

Do you know if there is another way to reference a lazy loaded module that is in sibling directory other than '../' that will work on AoT?

further info:

I have a home module and a dashboard module in sibling folders, and dashboard module is lazy loaded in to router-outlet of home module.

home routes

export const HomeRoutes: Routes = [
    {
        path: '', component: HomeComponent,
        children: [
            { path: '', loadChildren: '../+dashboard#DashboardModule'},
        ],
    }
];

dashboard routes

export const DashboardRoutes: Routes = [
    {
        path: '', component: DashboardComponent,
    }
];

both are loaded in their respective modules with RouterModule.forChild();

Thanks

glendaviesnz commented 7 years ago

Should have added - settings used are:

              options: {
                loader: 'async-import',
                genDir: 'compiled',
                aot: true
              }

and running on Windows.

shlomiassaf commented 7 years ago

It works fine in this test spec https://github.com/shlomiassaf/ng-router-loader/blob/master/test/test.spec.ts#L75

The logic to resolve paths is similar all the way...

I need a repo I can reproduce it with, I don't see any issue here.

The whole purpose of this loader is doing exactly that thing, very core level support so I think it's probably something in your configuration.

glendaviesnz commented 7 years ago

Thanks - did some debugging and was related to the fact that the top level app module was importing the home module, so its child lazy loaded routes were being resolved by AoT relative to app root rather then the home module - fixed for now by lazy loading home module as well instead of importing into app module.