我试图将Angular 2
项目转换为Angular-cli Project
在 app.routing.ts
中const appRoutes: Routes = [...
{
path: 'login',
loadChildren: 'app/components/login/login.module#LoginModule'
}...
]
所有其他路线均受AuthGuard
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
if(this.authService.isLoggedIn()) {
return true;
}
this.authService.redirectUrl = state.url;
this.router.navigate(['/login']);
return false;
}
开始时我收到描述性错误:
Error: Cannot find module 'app/components/login/login.module'.
at webpackEmptyContext (http://localhost:4200/main.bundle.js:43074:8)
at SystemJsNgModuleLoader.loadAndCompile (http://localhost:4200/main.bundle.js:51438:40)
at SystemJsNgModuleLoader.load (http://localhost:4200/main.bundle.js:51430:60)
at RouterConfigLoader.loadModuleFactory (http://localhost:4200/main.bundle.js:67227:128)
at RouterConfigLoader.load (http://localhost:4200/main.bundle.js:67218:81)
at MergeMapSubscriber.project (http://localhost:4200/main.bundle.js:73950:111)
at MergeMapSubscriber._tryNext (http://localhost:4200/main.bundle.js:66040:27)
at MergeMapSubscriber._next (http://localhost:4200/main.bundle.js:66030:18)
at MergeMapSubscriber.Subscriber.next (http://localhost:4200/main.bundle.js:42112:18)
at ScalarObservable._subscribe (http://localhost:4200/main.bundle.js:69099:24)
我无法提及使用Angular-cli
的loadingChildren工作方式不同。
我缺少什么
*****编辑**********
login.module.ts
import {NgModule} from "@angular/core";
import {FormsModule} from "@angular/forms";
import {LoginComponent} from "./login.component";
import {loginRouting} from "../../routes/login.routing";
import {CommonModule} from "@angular/common";
@NgModule({
imports: [
CommonModule,
FormsModule,
loginRouting
],
declarations: [
LoginComponent
]
})
export class LoginModule {}
相对路径:src / app / components / login / login.module.ts