Search code examples
angularangular2-routingangular2-router3

Angular2 RC5 - route after finish loading config file


I am writing Angular2 App using RC5.

When AppComponent load, I want application to request config file using http and and once its loaded I want app to navigate to the route specified?

How can I achieve that ?

There is 'canActivate' property on each route, but I would see that it has more to do with if I want to do something every time user navigate to new route. Mostly used for authentication purpose, where you want only few routes to be protected with Authentication but in my case I would like to load configuration when AppComponent load. Not on every route activation or navigation.

Hope I made my self clear what I am trying to achieve.


Solution

  • You can store in the canActivate guard that the initial re-navigation had been done and for subsequent calls only return true.

    You could configure the router with a single route

    { path: '**', InitComponent }
    

    and in InitComponent load your configuration, reconfigure the router (pass all routes) and then forward to the path initially requested.

    See also Angular 2 Dynamic Route Building & Component Level Permissions