2

My route is declared like this:

const routes: Routes = [
    {
        path: 'somepath',
        component: SomeComponent,
        canActivate: [LoginGuard],
        data: {
            showSidebar: true
        }
    }
];

Then, later on, in my NgModule imports, i load the route like this:

imports: [
    RouterModule.forChild(routes),
    ...
]

I'm wondering how I can access the data.showSidebar flag on route-change?

Thanks.

irfanka
  • 129
  • 1
  • 14

1 Answers1

-1
constructor(route:ActivatedRoute) {
  route.data.forEach(data => console.log(data.showSidebar));
}

See also Changing the page title using the Angular 2 new router

Community
  • 1
  • 1
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567