2016-11-03 4 views
7

私はRecipe Bookを持っているので、Recipiesのリストを持っています。レシピをクリックすると、ネストされたルートに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''を追加しませんでした。 Plunkerで再現できますか? –

+0

コンポーネントがあっても 'pathMatch:full'を追加する必要がありますか? – Daimz

答えて

8

このルートは無効であり、あなたはそれのためのエラーを取得する必要があります。

{ path: '' }, 

経路のいずれかcomponentredirectTo、又はchildrenを有する必要があります。

空のパスルートに子がない場合は、pathMatch: 'full'も必要です。私はあなたが何をしたいと思い

DummyComponentは、空のビューを持つコンポーネントである

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

です。 これらすべてのパスに同じDummyComponentを再利用できます。

+1

私はこの問題の周りでインターネットから騒々しい部分を探し出し、これまでのチュートリアルの中で重要な点を一つ間違っていました。彼らは '{path: ''}'を使っていますので、とても混乱しました学ぼうとしている。 – Daimz

+0

すべての問題を解決できますか、またはまだ期待どおりに機能しないことがありますか? –

+0

上記のコードを新しいルーティングで更新しました。 「レシピ帳>単一レシピ>成分」の間で移動できます。コンセントエラーはありません。しかし、私が「レシピ1」を訪問すると、成分が表示されません(これは、材料ボタンをクリックすると表示され、「レシピ - ブック/ 1 /レシピ/ 1 /ノート」に移動します)成分が示すボタン。完璧!それから私は「レシピ2」(材料はまだアクティブ)をクリックして、「レシピ2」を取得しますが、「レシピ1」の成分を使用します。 Ingredientsボタンをクリックすると、「Recipe 2s」の成分が読み込まれます。私が間違っている可能性のあるアイデア? – Daimz

関連する問題