2016-10-11 3 views
1

저는 게으른 로딩을 사용하여 Angular 2 프로젝트에서 작업했습니다. 잘 작동하지만 서버에서 모듈 이름을 가져온 다음 경로를 만들면되지만 작동하지 않습니다. 여기angular 2 게으른 로딩 - 서버의 경로

import { Routes, RouterModule } from '@angular/router'; 

function getRoutes(): Routes{ 
    let x: any = [ 
     {path: '', redirectTo: 'welcome', pathMatch: 'full'}, 
     {path: 'backend', loadChildren: 'app/backend/backend.module'} 
     ] 
    return x; 
} 

export const routes: Routes = routess(); 

export const routing = RouterModule.forRoot(routes); 

그리고이다, 내가 무엇이 필요합니까 :

import { Routes, RouterModule } from '@angular/router'; 

function getRoutes(): Routes{ 
let x: any; 

$.get("api/getRoutes", function(data) { 
    x = data; //object array from server 
}); 
    return x; 
} 

export const routes: Routes = routess(); 

export const routing = RouterModule.forRoot(routes); 

문제는 함수 getRoutes 서버의 결과 반환을 기다리고되지 않는다는 것을 여기

내가 가진 무엇 빈 데이터.

서버 데이터를 기다린 다음 경로에 데이터를 추가 할 수있는 방법이 있습니까?

답변

0

NgModule을 기본 라우팅 설정 (/welcome 등)으로 사용하고 다른 앱이 경로를로드하고 라우터 구성을 업데이트합니다. resetConfig()을 사용할 수 있습니다.

this.http.get('/api/getRoutes') 
    .subscribe(config => this.router.resetConfig(config)) 
+0

감사합니다. –