Angular 2,如果在路由 object 之前创建 children 的数组,则不会创建 children 路由的块

Angular 2, chunk for children routes not createds if create array of children befor Routes object

我的 children 路线在创建时效果很好:

let routes: Routes = [
    {
        path: '',
        component: MainComponent,
        children: [
            {path: 'a', loadChildren: '../+a/a.module.ts#AModule', canLoad: [AGuard]},
            {path: 'b', loadChildren: '../+b/b.module.ts#BModule', canLoad: [BGuard]}
        ]
    }
];

和为所有模块创建的块,当我像这样尝试 init children 之前,所有模块都停止工作,并且我没有用于此模块的块:

let children: Routes = [];

children.push({path: 'a', loadChildren: '../+a/a.module.ts#AModule', canLoad: [AGuard]})
children.push({path: 'b', loadChildren: '../+b/b.module.ts#BModule', canLoad: [BGuard]})

let routes: Routes = [
    {
        path: '',
        component: MainComponent,
        children: children
    }
];

这很奇怪,我认为这是相同的代码。

尝试将子项定义为通用数组,而不是键入 Router。

let children:any = [];

children.push({path: 'a', loadChildren: '../+a/a.module.ts#AModule', canLoad: [AGuard]})
children.push({path: 'b', loadChildren: '../+b/b.module.ts#BModule', canLoad: [BGuard]})

let routes: Routes = [
    {
        path: '',
        component: MainComponent,
        children: children
    }
];

结果我创建了 2 个环境文件第一个 environment.a.ts 有路由 a

export const environment = {
    ....
    {path: 'a', loadChildren: '../+a/a.module.ts#AModule', canLoad: [AGuard]}
}

第二个environment.b.ts有路线b

export const environment = {
    ....
    {path: 'b', loadChildren: '../+b/b.module.ts#BModule', canLoad: [BGuard]}
}

之后我可以使用我的路线:

import {environment} from "../../environments/environment";
let routes: Routes = [
    {
        path: '',
        component: MainComponent,
        children: environment.routes
    }
];

并分块正常创建