2017-10-06 24 views
0

이 내 라우터 공급 업체의 선언입니다 : 여기 Angular4 라우터 모듈 공급 업체 AOT

Error encountered resolving symbol values statically. Calling function 'getRoutes', function calls are not supported. Consider replacing the function or lambda with a reference to an exported function, resolving symbol RouterModuleProvider

이 RoutesFactory.buildRoutes

의 내용이다 : AOT에서 컴파일

@NgModule({ 
    imports: [RouterModule.forRoot(RoutesFactory.buildRoutes())], 
    exports: [RouterModule] 
}) 
export class RouterModuleProvider { }; 

,이 오류가 발생합니다

static buildRoutes() { 
    let returnRoutes: Routes = [ 
     { path: '', redirectTo: '/login', pathMatch: 'full' }, 
     { path: 'login', component: ViewsModule.LoginViewComponent } 
    ]; 

    let appendRoutes = (items: MenuItem[], routes: Routes) => { 
     for (let item of items) { 
      let route: Route = { 
       path: item.Path, component: item.Component, children: [] 
      }; 

      if (item.Children != null) 
       appendRoutes(item.Children, route.children) 

      routes.push(route); 
     } 
    }; 

    appendRoutes(RoutesFactory.getMenus(), returnRoutes); 

    return returnRoutes; 

} 

RoutesFactory.getMenus()는 정적 내부 개체 배열을 반환합니다. (백엔드에서로드 된 항목 없음)

이 문제를 해결할 수있는 방법이 있습니까?

+0

RoutesFactory.buildRoutes()에 무엇이 있습니까? –

+0

문제에 대한 자세한 내용을 제공하기 위해 내 자신의 질문을 편집했습니다. – gio

+0

이것은 라우팅을 수행하는 정말 이상한 방법입니다. 이럴 이유가 있니? – mast3rd3mon

답변

1

불행하게도 오류 메시지에서 알 수 있듯이 메타 데이터의 일부인 모든 내용 (정적으로 @NgModule(...) 선언)은 정적으로 해결할 수 있어야합니다. 즉, buildRoutes 함수에있는 것과 같은 논리는 없으며 정적 선언 만 가능합니다.

그러나 경로를 동적으로 정의하는 대안이있는 것으로 보입니다. 이 답변을 참조하십시오 : Dynamic routing based on external data.

+0

제안을 살펴 보겠습니다. 팁 고마워. – gio