Adding Child Routing Together
Adding Child Routing Together
1. in app-routing.module.ts
we'll add children routes on our recpes path:
{ path: "recipes", component: RecipesComponent },
Updated Code
{
path: "recipes", component: RecipesComponent,
children: [{ path: "", component: }]
},
remarks
we want to access http://localhost:4200/recipes/ nothing...
Then in recipe-start.component.html
{
path: "recipes", component: RecipesComponent,
children: [{ path: "", component: RecipeStartComponent}]
},
Then import
import { RecipeStartComponent } from './recipes/recipe-start/recipe-
start.component';
4. in recipes.component.html
We remove the below code
<ng-template #infoText>
<p>Please select a Recipe!</p>
</ng-template>
<router-outlet></router-outlet>
******************
{
path: "recipes", component: RecipesComponent,
children: [{ path: "", component: RecipeStartComponent },
{ path: ":id", component: RecipeDetailComponent }]
},
then import it
import { RecipeDetailComponent } from './recipes/recipe-detail/recipe-
detail.component';
ERROR MESSAGE
core.js:4352 ERROR TypeError: Cannot read property 'name' of undefined at
RecipeDetailComponent_Template (