2

I have a Router Configuration for my angular2 app.
Here is the code

import { provideRouter, RouterConfig } from '@angular/router';
import { HomeComponent } from "./home.component";

const routes: RouterConfig = [ // I want this data by api call, 
  { path: 'home', component: HomeComponent }
  { path: '', redirectTo: '/home', pathMatch: 'full' }
];

export const appRouterProviders = [
  provideRouter(routes)
];

I want my data to get from database from mongodb. I have already setup the database and through an api call

http://localhost:3000/getAppRoutes 

it is already returning data in below format, means array of objects,

[
  { path: 'home', component: HomeComponent }
  { path: '', redirectTo: '/home', pathMatch: 'full' }
]

How do I fetch data from database but not as static configurations ?

Thanks

  • You can use `router.resetConfig` http://stackoverflow.com/questions/37270088/new-angular2-router-configuration/38096260#38096260 to update the router configuration at runtime but you won't be able to load component types from MongoDB. You need to replace names with types before you pass it to `router.resetConfig` – Günter Zöchbauer Jul 26 '16 at 13:29
  • or wait for RC5 and update on router with that version. It will solve lots of such usecases through AppModule and RouterModule along with lazy loading – Siraj Jul 26 '16 at 15:29

0 Answers0