我已经设置了我的应用程序,以便我有Recipe Book
一个列表Recipies
,当我单击食谱时,它会Recipe Details
在嵌套路线中显示。然后,它还有一个按钮,单击该按钮可将成分加载到Recipes Details
.
到目前为止,路由似乎有效,除非我尝试导航到另一个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' }
];