问题
I'm trying to implement RC5 changes in my app and I'm getting some trouble when lazy loading modules in my routing.
This is the structure in my app for the affected files:
/app
/components/meda/meda.module.ts
/components/meda/meda.routing.ts
app.routing.ts
And this is my app.routing.ts
const routes: Routes = [
{
path: '',
redirectTo: 'init',
pathMatch: 'full'
},
{
path: 'init',
loadChildren: './components/init/init.module#InitModule'
},
{
path: 'meda',
loadChildren: './components/meda/meda.module#MedaModule'
}
];
and my meda.module.ts
@NgModule({
imports: [ routing ],
})
export class MedaModule { }
My application loads fine into the init route because bootstrap loads InitModule, but once I try to navigate to meda I get the following
GET http://localhost/web/components/meda/meda.module 404 (Not Found)
It seems it can't find the module location. I also tried with
loadChildren: 'app/components/meda/meda.module#MedaModule'
but no luck; any idea what I'm doing wrong?
Thanks
回答1:
I had the same issue, I changed my path according to comment of Thorsten Viel. Here is my folder structure to illustrate;
/wwwroot
/app
/scripts
My .ts files are under 'wwwroot/app' folder. I use 'gulp-typescript' to transpile .ts files into .js under 'wwwroot/scripts' folder. For example, if your init.module.ts path is: wwwroot/app/components/init/init.module and your .js file is transpiled into: wwwroot/scripts/components/init/init.module, you should specify like this:
loadChildren: 'wwwroot/scripts/components/init/init.module#InitModule'
It should work, I hope it helps.
回答2:
Write the path without leading . or ./ or /
loadChildren: 'components/init/init.module#InitModule'
The start point of address is the location of your html file.
来源:https://stackoverflow.com/questions/38918992/angular2-rc5-lazy-load-routing-can%c2%b4t-find-module