2016-11-17 73 views
1

我尝试使用Lazyload路由但嵌套。但我仍然得到它在2级路线中找不到模块的错误。Angular 2 - 在嵌套路由中找不到模块

这里是我的结构:

app.module.ts:

import { BrowserModule } from '@angular/platform-browser'; 
import { NgModule } from '@angular/core'; 
import { FormsModule } from '@angular/forms'; 
import { HttpModule } from '@angular/http'; 
import { routing } from './app.routes'; 
import { AppComponent } from './app.component'; 
import { RouterModule } from '@angular/router'; 

@NgModule({ 
    declarations: [ 
    AppComponent, 
    AuthComponent 
    ], 
    imports: [ 
    BrowserModule, 
    FormsModule, 
    HttpModule, 
    routing 
    ], 
    exports: [RouterModule], 
    providers: [], 
    bootstrap: [AppComponent] 
}) 
export class AppModule { } 

app.routes.ts

import { Router, RouterModule} from '@angular/router'; 
import { AuthGuard } from './Auth/Services/auth-guard.service'; 
import { AuthComponent } from './Auth/auth.component'; 

export const routing = RouterModule.forRoot([ 
    { path: '', redirectTo: "portal", pathMatch: 'full'}, 
    { path: 'portal', loadChildren: './Portal/portal.module#PortalModule'}, 
    { path: '**', redirectTo: "portal"} 
]) 

门户网站/ portal.module.ts:

import { NgModule } from '@angular/core'; 
import { routing } from './portal.routes'; 
import { PortalComponent } from './portal.component'; 
import { FormsModule,ReactiveFormsModule } from '@angular/forms'; 
import { RouterModule } from '@angular/router'; 
import { CommonModule } from '@angular/common'; 

@NgModule({ 
    imports: [ 
    CommonModule, 
    FormsModule, 
    ReactiveFormsModule, 
    routing 
    ], 
    exports: [ RouterModule ], 
    declarations: [ 
    PortalComponent 
    ], 
    providers: [ 
    ] 
}) 
export class PortalModule { } 

Portal/portal.routes.ts:

import { Router, RouterModule} from '@angular/router'; 
import { PortalComponent } from './portal.component'; 

export const routing = RouterModule.forChild([ 
    { path: '', redirectTo: "reports"}, 
    // This Part doesn't work 
    { path: 'reports', component: PortalComponent, loadChildren: './Portal/Test/test.module#TestModule'}, 
    // -- 
    { path: '**',component: PortalComponent, pathMatch: 'full'} 
]) 

门户/测试/ test.module.ts:

import { NgModule } from '@angular/core'; 
import { routing } from './test.routes'; 
import { TestComponent } from './test.component'; 
import { FormsModule,ReactiveFormsModule } from '@angular/forms'; 
import { RouterModule } from '@angular/router'; 
import { CommonModule } from '@angular/common'; 

@NgModule({ 
    imports: [ 
    CommonModule, 
    FormsModule, 
    ReactiveFormsModule, 
    routing 
    ], 
    exports: [ RouterModule ], 
    declarations: [ 
    TestComponent 
    ], 
    providers: [ 
    ] 
}) 
export class TestModule { } 

门户/测试/ test.routes:

import { Router, RouterModule} from '@angular/router'; 
import { TestComponent } from './test.component'; 

export const routing = RouterModule.forChild([ 
    { path: '', redirectTo: "reports"}, 
    { path: 'reports', component: TestComponent}, 
]) 

我的错误:

EXCEPTION: Uncaught (in promise): Error: Cannot find module './Portal/Test/test.module'. 
Error: Cannot find module './Portal/Test/test.module'. 

我问题现在是他为什么找不到该模块? 我也尝试过其他路径,但这是我唯一能真正工作的人,我认为。

我需要做什么来修复或角2不能做到这一点?

(只是testet错误与NG服务无法与建设|使用Chrome Testet)

+0

这个路径工作吗? {path:'reports',component:PortalComponent,loadChildren:'./Test/test.module#TestModule'}? –

+0

不,我真的试过一切 –

+0

为什么你有这个组件:PortalComponent?在{path:'reports',component:PortalComponent,loadChildren:'./Test/test.module#TestModule'} –

回答

0

不知道这是否会帮助,但我做模块的方式是每一个模块文件名index.ts,只是指定引用它们时文件夹的路径。我从来没有遇到任何模块没有找到问题。有关如何加载异步模块的示例,请参阅https://github.com/AngularClass/angular2-webpack-starter/tree/master/src/app

+0

你的git不是一样的构造因为只有1个级别的孩子 –

0

这个问题是在旧的@角/路由器我现在更新到3.2.0 befor我有3.1.0