2016-11-03 2 views
7

Recipies의 목록이있는 Recipe Book을 갖도록 앱을 설정했습니다. 그러면 레서피를 클릭하면 중첩 된 경로에 Recipe Details이 표시됩니다. 또한이 버튼을 클릭하면 Recipes Details 내부의 중첩 된 경로에있는 재료가로드됩니다.각도 2 던지기 오류 : 아울렛이 활성화되지 않았습니다.

Recipe으로 이동하려고 시도한 경우를 제외하고는 지금까지 라우팅이 작동하는 것처럼 보입니다. Ingredients 트레이 (경로)가 활성화되면 다음은 레시피를 변경하고 난 다음 시도하고 이동하면 나는 다음과 같은 오류 얻을 (재료를 열지 않고)는 Ingredients 노선을 축소

Uncaught (in promise): Error: Outlet is not activated 
Error: Outlet is not activated 

그것은 내가 같은 모습을 라우터에 Ingredients이 활성화되어 있어야합니다. 그렇지 않으면 중첩 된 경로를 이해할 수 없습니다. 그게 전부지만, 그것을 해결하는 방법이나 내가 잘못했을 때 확실하지.

단일 조리법 책 page.component.html

<app-tray class="recipe-list"> 
    <app-recipe-list [recipe]="recipe"></app-recipe-list> 
</app-tray> 
<router-outlet></router-outlet> 

조리법 detail.component.html

<app-tray class="recipe"> 
    The routing has worked and loaded recipe. 
</app-tray> 
<router-outlet></router-outlet> 

성분-list.component.html

<app-tray class="ingredients-list"> 
    Recipe Ingredients have loaded. 
</app-tray> 

app.routes.ts은은 (업데이트)

export const routerConfig : Route[] = [ 
    { 
    path: 'recipe-books', 
    children: [ 
     { 
     path: ':id', component: SingleRecipeBookPageComponent, 
     children: [ 
      { 
      path: 'recipes', 
      children: [ 
       { path: ':id', component: RecipeDetailComponent, 
       children: [ 
        { path: '', component: IngredientsListComponent }, 
        { path: 'ingredients', component: IngredientsListComponent } 
       ] 
       }, 
       { path: 'new', component: IngredientsListComponent }, 
       { path: '', component: RecipeDetailComponent } 
      ] 
      }, 
      { path: '', redirectTo: 'recipes', pathMatch: 'full' } 
     ] 
     }, 
     { path: '', component: RecipeBooksPageComponent } 
    ] 
    }, 
    { path: 'ingredients', component: IngredientsComponent }, 
    { path: '', redirectTo: 'recipe-books', pathMatch: 'full' }, 
    { path: '**', redirectTo: 'recipe-books', pathMatch: 'full' } 
]; 
+0

이러한 경로는 무엇입니까? –

+0

2 개의 빈 경로 하위 경로에'pathMatch : 'full'을 추가하지 않았습니다. 플 런커에서 재생산 할 수 있습니까? –

+0

컴포넌트가 있어도'pathMatch : full'을 추가해야합니까? – Daimz

답변

8

이 경로가 잘못되었습니다 그리고 당신은 그것을 오류가 발생합니다.

{ path: '' }, 

라우트는 중 하나 component하는 redirectTo, 또는 children 있어야합니다.

빈 경로 경로에 자식이 없으면 pathMatch: 'full'이어야합니다.

나는 당신이 원하는 것은 DummyComponent 빈 볼 수있는 구성 요소입니다

{ path: '', component: DummyComponent, pathMatch: 'full' }, 

것 같다. 이러한 모든 경로에 대해 동일한 DummyComponent을 재사용 할 수 있습니다.

+1

선명도를 주셔서 감사 드리며, 인터넷을 통해이 문제를 둘러 보았습니다. 그리고 지금까지 내가 한 지침서에서 중요한 한 점을 놓쳤습니다. 그들은'{path : ''}'를 사용하여 매우 혼란 스럽습니다. 배우려고. – Daimz

+0

모든 문제를 해결할 수 있습니까? 아니면 여전히 예상대로 작동하지 않는 부분이 있습니까? –

+0

위의 코드를 새로운 라우팅으로 업데이트했습니다. 이제 '조리법 책> 단일 조리법> 재료'출구 오류가 발생하지 않습니다.하지만 이제 '조리법 1'을 방문하면 재료가 표시되지 않습니다 (재료 버튼을 클릭하면 '조리법 책/1/조리법/1/메모'로 이동합니다.)을 클릭하면 표시됩니다. 재료가 보여주는 버튼. 완전한! 그런 다음 'Recipe 2' (재료는 여전히 활성 상태 임)를 클릭하면'Recipe 2'가 나오지만 'Recipe 1' Ingredients가 있습니다. 성분 버튼을 클릭하면 현재 'Recipe 2s' 성분이로드됩니다. 내가 잘못 될 수있는 어떤 생각? – Daimz

관련 문제