Angular 5将数据传递到子路由

时间:2017-12-04 16:51:29

标签: javascript angular angular-ui-router

在我对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实例)是空的。对于路径',两个组件中成功传递的数据。

我不知道如何解决它,请帮助我。

1 个答案:

答案 0 :(得分:0)

检查您的激活路线firstChild属性。