Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 7 routes concat导致编译错误_Angular_Typescript_Concat - Fatal编程技术网

Angular 7 routes concat导致编译错误

Angular 7 routes concat导致编译错误,angular,typescript,concat,Angular,Typescript,Concat,首先-仅供参考,路由模块设置为: @NgModule({ imports: [RouterModule.forRoot(ALL_ROUTES)], exports: [RouterModule], providers: [] }) export class AppRoutingModule {} 将所有路由放置在名为“all_routes”的1个数组中,并将该数组传递给AppRoutingModule-imports:[RouterModule.forRoot(all_routes

首先-仅供参考,路由模块设置为:

@NgModule({
  imports: [RouterModule.forRoot(ALL_ROUTES)],
  exports: [RouterModule],
  providers: []
})
export class AppRoutingModule {}
将所有路由放置在名为“all_routes”的1个数组中,并将该数组传递给AppRoutingModule-imports:[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
    ];
你也可以试试

const supportedGames: Route[] = [
    {
        path: "pubg",
        component: LoginComponent
    }
];

const routes: Routes = [
    {
        path: "",
        component: LoginComponent,
    },
    {
        path: "login",
        component: LoginComponent,
    },
    {
        path: "main",
        component: MainViewComponent,
        children: ([
            {
                path: "game-list",
                component: GameListComponent,
            }
        ] as Route[]).concat(supportedGames)
    },
    {
        path: "**",
        redirectTo: ""
    }
];

尝试类似于导出const ALL_ROUTES:ROUTES=[…ROUTES 1,…ROUTES 2]似乎正在工作。非常感谢。