angular - Angular 7 路由 concat 导致编译错误
问题描述
首先 - 仅供参考,路由模块设置为:
@NgModule({
imports: [RouterModule.forRoot(ALL_ROUTES)],
exports: [RouterModule],
providers: []
})
export class AppRoutingModule {}
将所有路由放在名为“ALL_ROUTES”的 1 个数组中并将该数组传递给 AppRoutingModule - 导入:[RouterModule.forRoot(ALL_ROUTES)],工作正常:
export const ALL_ROUTES: Routes = [
{path: 'route1', component: FirstComponent},
{path: 'route2', component: SecondComponent},
{path: 'route3', component: ThirdComponent},
{path: 'route4', component: FourthComponent}
];
所以,上面的代码工作正常。但是,如果我们有 2 个数组并像这样连接它们:
export const ROUTES1: Routes = [
{path: 'route1', component: FirstComponent},
{path: 'route2', component: SecondComponent}
];
export const ROUTES2: Routes = [
{path: 'route3', component: ThirdComponent},
{path: 'route4', component: FourthComponent}
];
export const ALL_ROUTES: Routes = ROUTES1.concat(ROUTES2);
我们得到一个编译错误:
ERROR in Cannot read property 'loadChildren' of undefined
这里已经提出了几个类似的问题,但没有解决这个问题。有没有可能的解决方案?可能是对正在发生的事情的解释?
解决方案
对于那些正在寻找有答案的帖子的人——正如丹尼尔上面所建议的那样,这似乎是可行的。如果有任何潜在问题,请发表评论。
export const ALL_ROUTES: Routes =
[
...ROUTES1,
...ROUTES2
];
推荐阅读
- r - 如何选择在R中满足条件的行?
- java - 从片段返回到上一个主片段的按钮箭头
- python - Webdrivers 不使用 Selenium (Python)
- python - 复杂的 Pandas 选择
- swift - 如何根据自定义日期参数划分数据
- matlab - dSPACE ControlDesk 错误 - 没有可用内存。[0.000]
- axon - Axon 4 - Kafka ext 4.0.RC3 出现启动错误
- python - Mysql问题创建和读取db问题
- microsoft-graph-api - 无法使用 Graph API 从重复事件中检索 cancelledOccurences
- c# - 向相机方向旋转第三人称?