2016-09-07 4 views
8

을 :각도이 개 중첩 된 경로 해결 실행 예를 들어

const appRoutes: Routes = [ 
    { 
     path: "", 
     component: AppComponent, 
     resolve: { 
      app: AppResolver 
     }, 
     children: [ 
      { 
       path: "", 
       component: NestedComponent, 
       resolve: { 
        subscribers: NestedResolver 
       } 
      } 
     ] 
    } 
]; 

및 다음 리졸버 :

export class AppResolver implements Resolve<any> { 
    constructor(private appService: AppService) {} 
    resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<any> { 
     return this.appService.getAppData(); 
    } 
} 
export class NestedResolver implements Resolve<any> { 
    constructor(private nestedService: NestedService) {} 
    resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<any> { 
     console.log(route.parent.data); //when this is executed route.parent.data is empty :(
     return this.nestedService.getNestedData(); 
    } 
} 

응용 프로그램 bootstraping NestedResolver 및 후 AppResolver가 먼저 실행되고 t를 만든다. 상속인은 동시에 요청합니다.

코드를 변경하고 NestedResolver가 AppResolver가 해결되기를 기다리고 AppResolver 해결 된 데이터에 액세스 할 수 있도록 구현할 수 있습니까?

각도 2 RC6, 각도 라우터 3.0.0-rc.2

+1

이 답변을 찾을 수 있었습니까? –

답변

3

나는이 질문은 꽤 오래 알고 있지만 단지의 경우 사람에 (나 같은)이 우연히 발견.

이것은 알려진 버그이며 이후 수정되었습니다. 라우터 버전을 2.1.0 이상 또는 그 이상으로 업데이트하면 성공할 수 있습니다. 참조 용으로 여기에 해당하는 issue on githubassociated fix