2

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?

user3602300
  • 129
  • 7
  • after doing some more analysis, I figured it might be related to lazy loading itself. Because with the same code, if I move the data property to the first route(path: ''), i get the properties within the data I am not sure why i am not getting the second route. Can someone please help – user3602300 Dec 06 '21 at 19:31

0 Answers0