I have an Angular 5 app that retrieves content from Contentful. Some of this content is routes. I would like to set these inside a child RoutingModule
as follows:
const myRoutes: Routes = [
{ path: '', component: BaseComponent },
{ path: '**', component: FailComponent }
];
@NgModule({
RouterModule.forChild(myRoutes),
...
})
export class MyRoutingModule {
routesFromContentful = retrieveRoutesFromContentful();
routes.forEach((route:string) => {
myRoutes.push({ path: route, component: GenericComponent });
}
}
To be clear:
- I am mapping all routes to the same component,
GenericComponent
. This is intended. - I have no problem retrieving the routes from Contentful.
- The issue is that the new routes I push into
myRoutes
are not recognized.
Is there a way to have these routes recognized? Are they not recognized because the exported class comes after @NgModule
?