angular access route._loadedConfig in RouteConfigLoadEnd-Handler

Viewed 1488

How can I access the route._loadedConfig member ? It is always undefined.

const a = (route as any)._loadedConfig;
const a =  (<any>route )._loadedConfig;
const a =  (<any>route )['_loadedConfig'];

None of these work.

VS-Code shows the value in debug-window:

debug window

1 Answers

Assuming you want access to the routes object of the _loadedConfig ( as the module-object is mostly internal angular-stuff you shouldn't really mess around ) i would advice not to access this directly as it's not a part of a public api and so might change or being otherwise unrelaiable.

To access the child-roots of a lazy-loaded module on load-time, you could do something like the following:

Create a root-injected service

@Injectable({
  providedIn: 'root'
})
export class LazyLoadedChildRouteService {
    public updateLazyLoadedRoutes( childRoutes: Routes ){ ... }
    // CONSTRUCTOR
    constructor( ... ){ ... }
}

In the Module-File:

export const lazyLoadedRoutes: Routes = [
    {
      path: 'lazyRoute',
      component: LazyLoadedComponent
    },
]

@NgModule({
  ...
  imports: [
    RouterModule.forChild( lazyLoadedRoutes ),
  ],
  ...
})
export class LazyLoadedModule {
  /** CONSTRUCTOR */
  constructor(
    public $translateUrlService: FgTranslateRouterService
  ) {
    this.$translateUrlService.addChildModuleRoutes( lazyLoadedRoutes );
  }
}
Related