I have a module with the routes defined something like below.
const routes: Routes = [
{
path: '',
pathMatch: 'full',
component: RoleListViewComponent
},
{
path: RolesRoutes.addNewRole,
component: ManageRoleComponent,
data: {
privileges: PRIVILEGES_SPECS.managedEnterpriseSettings,
newRole: true
}
}
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class RoleRoutingModule { }
The problem I am facing is, with passing data into the addNewRole path. It gives me empty object when I try to access the same from within component. I did lot of search figured this could be due to lazy load of this module like below
import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
import { RolesRoutes } from './user-management.constants';
@NgModule({
imports: [
RouterModule.forChild([
/* {path: '', pathMatch: 'full', component: InsertYourComponentHere} */
{
path: RolesRoutes.roles,
loadChildren: () => import('./role/role.module').then(m => m.RoleModule),
}
])
]
})
export class UserManagementModule {}
So to confirm I removed lazy load above, and i could see the data coming through. The question now i have, can I not define data in the child routes inside a lazily loaded module. is this not the right approach to follow? Any suggestions?