1000ISLANDS
1000ISLANDS

Reputation: 37

Angular 5 passing data to child route

In my project on Angular 5, routing config looks like this:

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
    }
];

In theory, BBData should passed on BBComponent, and BCData on BCComponent, but object this.route.snapshot.data (this.route instance of ActivatedRoute) is empty. For path 'a', data passed in both component successfully.

I have not idea how to fix it, please, help me.

Upvotes: 1

Views: 1654

Answers (1)

Adawg
Adawg

Reputation: 378

Check your activated route firstChild property.

Upvotes: 1

Related Questions