Fel*_*lix 3 concat typescript angular
首先 - 仅供参考,路由模块设置为:
@NgModule({
imports: [RouterModule.forRoot(ALL_ROUTES)],
exports: [RouterModule],
providers: []
})
export class AppRoutingModule {}
Run Code Online (Sandbox Code Playgroud)
将所有路由放在 1 个名为:'ALL_ROUTES' 的数组中,并将该数组传递给 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}
];
Run Code Online (Sandbox Code Playgroud)
所以,上面的代码工作正常。但是,如果我们有 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);
Run Code Online (Sandbox Code Playgroud)
我们得到一个编译错误:
ERROR in Cannot read property 'loadChildren' of undefined
Run Code Online (Sandbox Code Playgroud)
这里已经问了几个类似的问题,但没有解决这个问题。有可能的解决方案吗?可能是对正在发生的事情的解释?
对于那些正在搜索带有答案的帖子的人 - 正如上面 Danil 所建议的那样,这似乎是有效的。如果有任何潜在问题,请发表评论。
export const ALL_ROUTES: Routes =
[
...ROUTES1,
...ROUTES2
];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
811 次 |
| 最近记录: |