loadChildren导致无法找到模块

时间:2016-12-05 17:51:40

标签: angular angular-cli

我试图将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

0 个答案:

没有答案