在嵌套路由中使用占位符,确保父组件中的
在 app-routing.module.ts 文件中定义嵌套路由:
const routes: Routes = [
{
path: 'parent',
component: ParentComponent,
children: [
{
path: 'child',
component: ChildComponent
}
]
}
];
在 parent.component.html 中使用占位符:
在父组件的模板中使用一个包含占位符的
注意:如果在父组件模板中省略了占位符,则嵌套路由不会正确工作,并且页面将会显示空白。