[英]Angular 2 - Cannot find module in nested routes
I try to use Lazyload routes but nested. 我尝试使用Lazyload路由但嵌套。 But i still get the error that it do not find the module in the 2 level route.
但我仍然得到错误,它没有找到2级路线中的模块。
Here is my construct: 这是我的构造:
app.module.ts: 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 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/portal.module.ts: 门户/ 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: 门户/ 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'}
])
Portal/Test/test.module.ts: 门户网站/测试/ 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 { }
Portal/Test/test.routes: 门户网站/测试/ 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},
])
My error: 我的错误:
EXCEPTION: Uncaught (in promise): Error: Cannot find module './Portal/Test/test.module'.
Error: Cannot find module './Portal/Test/test.module'.
My Question is now why he do not find the Module ? 我的问题现在是他找不到模块的原因? I tried also other Paths but this i the only one which can really work i think.
我也尝试过其他路径,但这是我认为唯一可以真正起作用的路径。
What i need to do to fix or is angular 2 not able to do this ? 我需要做什么来修复或角度2无法做到这一点?
(The error is just testet with ng serve not with build | Testet with Chrome) (错误只是测试与ng服务不与构建| Testet与Chrome)
Not sure if this could help but the way I do modules is to name every module file index.ts and just specify the path to the folder when referencing them. 不确定这是否有用,但我执行模块的方法是将每个模块文件命名为index.ts,并在引用它们时指定文件夹的路径。 I have never had any issues with modules not being found.
我从来没有遇到过没有找到模块的任何问题。 Have a look at https://github.com/AngularClass/angular2-webpack-starter/tree/master/src/app for an example in how to load async modules.
有关如何加载异步模块的示例, 请查看https://github.com/AngularClass/angular2-webpack-starter/tree/master/src/app 。
这个问题出现在旧的@ angular /路由器上,我现在更新到3.2.0,因为我有3.1.0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.