[英]how to use router-outlet in a proper way
嗨,我有以下代码:app.routing.module
const routes: Routes = [
{path: '', redirectTo:'/head', pathMatch:'full'},
{path:'head',component: HeadComponent},
{path:'main',component: MainComponent},
];
头上有:
<router-outlet></router-outlet>
它应该自动导航到main,但不是。 我需要做空所有组件的根.regards
头中的路由器出口只会渲染头子,而您根本没有。
您的路线已设置为自动在应用程序组件的路由器出口中渲染头部。 Head没有孩子,因此不会渲染main。 您需要在head的子级中添加main。
const routes: Routes = [
{path: '', redirectTo:'/head', pathMatch:'full'},
{
path:'head',
component: HeadComponent,
children: [
{path:'',component: MainComponent}
]
}
];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.