Angular 7路由连接导致编译错误

标签 angular typescript 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

这里问了几个类似的问题,但没有解决这个问题。有可能的解决方案吗?可能是对正在发生的事情的解释?

最佳答案

对于那些正在搜索有答案的帖子的人 - 正如 Danil 上面所建议的那样,这个接缝很有用。如果有任何潜在问题,请发表评论。

export const ALL_ROUTES: Routes =
    [
      ...ROUTES1,
      ...ROUTES2
    ];

关于Angular 7路由连接导致编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54195192/

相关文章:

python-3.x - 在 Pandas 中将多列合并为一列

arrays - Swift3:泛型扩展中的类型推断

angular - 类型 'number' 不可分配给类型 '(...items: any[]) => number'

Angular 4,自定义错误处理程序无法识别自定义错误

reactjs - Typescript 找不到导入类型 Action

TypeScript 函数参数泛型

angular - 通过 Protractor 在 ion-textarea 中发送输入 - ionic 4

node.js - Json-server 的 Rest API 问题

html - 头部如何向左显示

r - 将数据帧组合在两个不同的列表中,这些列表以 R 中的元素名称为键