【发布时间】:2017-03-01 03:28:28
【问题描述】:
我正在尝试在我的应用中实现延迟路由。
我有一个非常大的项目,当它在路由器弃用时,我使用了 AsyncRoute,但现在它被删除了。
所以我尝试实现最新的延迟加载,但我遇到了问题 RangeError: 超出最大调用堆栈大小 我做错了什么?我按照说明完成了所有代码。
请看一下
遭遇模块
import { NgModule } from '@angular/core';
// import { CommonModule } from '@angular/common';
/* --------------- !System modules --------------- */
import { SharedModule } from 'sharedModule'; //There is a lot of shared components/directives/pipes (over 60) and it re-exports CommonModule so I can't avoid it
/* --------------- !App outer modules --------------- */
import { EncountersComponent } from './encounters.component';
// import { PassCodeComponent } from '../../shared/components/passcode/passcode.component';
@NgModule({
imports: [ SharedModule ],
declarations: [ EncountersComponent],
exports: [ EncountersComponent ],
})
export class EncountersModule { }
这是我的 app.routing.module
import { NgModule } from '@angular/core';
// import { ModuleWithProviders } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { ImagingComponent } from '../modules/index';
import { DashboardComponent } from '../modules/index';
import { PrescriptionNoticesComponent } from '../modules/index';
// import { EncountersComponent } from "../modules/encounters/encounters.component";
import { ScheduleComponent } from "../modules/schedule/schedule.component";
import { AdminComponent } from '../modules/index';
@NgModule({
imports: [
RouterModule.forRoot([
{
path: '',
component: DashboardComponent,
data: { label: 'Dashboard' }
},
{
path: 'encounters',
// component: EncountersComponent,
loadChildren: 'production/modules/encounters/encounters.module#EncountersModule',
data: { label: 'Encounters' }
},
{
path: 'admin',
component: AdminComponent,
data: { label: 'Admin' }
}
])
],
exports: [
RouterModule
]
})
export class AppRoutingModule {}
// const appRoutes: Routes = [
// {
// path: 'imaging',
// component: ImagingComponent,
// data: { label: 'Imaging' }
// },
// {
// path: '',
// component: DashboardComponent,
// data: { label: 'Dashboard' }
// },
// {
// path: 'prescription_notices',
// component: PrescriptionNoticesComponent,
// data: { label: 'Prescription Notices' }
// },
// {
// path: 'encounters',
// component: EncountersComponent,
// data: { label: 'Encounters' }
// },
// {
// path: 'schedule',
// component: ScheduleComponent,
// data: { label: 'Schedule' }
// },
// {
// path: 'admin',
// component: AdminComponent,
// data: { label: 'Admin' }
// }
// ];
//
// export const appRoutingProviders: any[] = [
//
// ];
//
// export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes);
【问题讨论】:
-
可能是因为我的遭遇模块没有任何路由
-
可能尝试删除 cmets。当我在我正在处理的应用程序中将我的路由器更新为当前路由器时,我从旧路由器中评论了一堆东西,因为我不想丢失它。删除 cmets 后,一些奇怪的错误消失了。虽然我的所有 cmets 都在我的代码顶部,所以我不确定这是否适用于此。
-
感谢弗兰克的帮助!
-
很高兴成功了!我发布了答案,以便人们可以更轻松地找到它。在更新时,同样的问题让我几乎一整天都感到困惑。
标签: angular typescript angular2-routing