Angular2 RC5 lazy load routing can´t find module

早过忘川 提交于 2019-12-12 23:13:42

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!