I try to build dynamic routes from angular2 (choosing a configuration route from the server), after that I analyze it and generate instructions for the component route (I have parent config and child routes to different components, because I do not know how to determine the route for the child component into one main.app.ts file).
The problem is when the application starts and tries to create routes config and routeGenerator does not yet create routes (async delay) can t parse routes data (because async delay, so routesData undefined now) and app is crashig. I don t parse routes data (because async delay, so routesData undefined now) and app is crashig. I don t know what to do with it. Looking for a lifecycle hood (some like @ Angular2BeforeAppStarted), but you haven’t found anything.
import {Component, Input, OnChanges} from 'angular2/core'; import {RouteConfig, RouterOutlet, ROUTER_DIRECTIVES, Router} from 'angular2/router'; import {routeGenInstance} from '../../config/routes/patient_routes'; protected const BUILT_MODULE_PATH: string = '/built/modules/patients/'; @Component({ template: ` <router-outlet ></router-outlet> `, directives: [RouterOutlet, ROUTER_DIRECTIVES] }) @RouteConfig(routeGenInstance.getRouteDefinitions()) export class PatientsComponent { @Input(); constructor() {} }
I also try to update the routes in the same way (but the application crashes immediately because my navigation link in the navigation component does not have the correct link path)
import {RouteConfig, RouterOutlet, ROUTER_DIRECTIVES, Router} from 'angular2/router'; constructor( private router: Router ) { router.config([ routeGenInstance.getRoutesDefinition() ]) }
Route definitions use an Async loader, so they are correct and work without asynchronous delay. I do not know how to make angular wait for the route definitions and start the application launch.
Please help me. Thanks.
UPD:
@Thierry thank you very much for your help again. You are a terrific friend and mentor. Last question (last). Can you tell me how I can define routeConfig in a single application file with a child routine definition? This is mean. I have main level routes to application files.
{ path: '/', name: 'Dashboard', component: DashboardComponent, useAsDefault: true }, { path: '/patients/...', name: 'Patients', component: PatientsComponent },
and Patient Components in Patients Component (@RouteConfig)
{ path: '/', // root is appRoot/patients/... name: 'PatientsList', component...}, { "name": "Chart", "path": "/chart/:id", component... },
How to determine the configuration of this route in only one app.file? (How to configure a route using additional routing in a single file)?