在我对Angular 5的项目中,路由配置如下所示:
const routes: Routes = [
{
path: 'a',
component: MainComponent,
children: [
{
path: 'ab',
component: ABComponent
},
{
path: 'ac',
component: ACComponent
}
],
data: AData // array of objects
},
{
path: 'b',
component: MainComponent,
children: [
{
path: 'bb',
component: BBComponent,
data: BBData // array of objects
},
{
path: 'bc',
component: BBComponent,
data: BCData // array of objects
}
],
data: extraData // if I put it on, extraData will be both in BBComponent and BCComponent
}
];
理论上,BBData应该传递给BBComponent上的BBComponent和BCData,但是对象this.route.snapshot.data(this.route ActivatedRoute实例)是空的。对于路径',两个组件中成功传递的数据。
我不知道如何解决它,请帮助我。
答案 0 :(得分:0)
检查您的激活路线firstChild属性。