Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 角度路由器重定向到第一个选项_Angular_Angular Routing - Fatal编程技术网

Angular 角度路由器重定向到第一个选项

Angular 角度路由器重定向到第一个选项,angular,angular-routing,Angular,Angular Routing,我一直在尝试重定向到第一个sectionId为空的子路由 例如:导航到/docs需要重定向/docs/第一步 const DOCUMENTATION_ROUTES: Routes = [ { path: '', component: DocumentationPage, resolve: { data: DocumentationResolver }, children: [{ path: ':id', component: DocumentationDeta

我一直在尝试重定向到第一个sectionId为空的子路由

例如:导航到/docs需要重定向/docs/第一步

const DOCUMENTATION_ROUTES: Routes = [
  {
    path: '',
    component: DocumentationPage,
    resolve: { data: DocumentationResolver },
    children: [{ path: ':id', component: DocumentationDetailComponent }]
  }
]; 
DocumentationResolver具有页面(部分)所需的所有数据

@Injectable()
导出类DocumentationResolver实现解析{
建造师(
私人文档服务:文档服务,
专用词汇服务:词汇服务,
专用路由器
) {}
解析(路由:ActivatedRouteSnapshot):可观察{
返回叉连接(
此.documentationService.getDocumentation()文件,
this.glossaryService.getGlossary()
).烟斗(
点击(([文档])=>{
//这是可行的,但会打两个电话
const firstSectionTitle:string=文档[0]。标题导航;
如果(!route.firstChild){
this.router.navigate(['/docs',firstSectionTitle]});
}
})
);
}
}
文档页面:带有侧栏的条目页面,其中包含各节。
DocumantationDetailComponent:呈现选定节的子组件。此外,它注入DocumentationResolver以获取数据。

您的路由配置:

const DOCUMENTATION_ROUTES: Routes = [
  {
    path: '',
    component: DocumentationPage,
    resolve: { data: DocumentationResolver },
    children: [{ path: ':id', component: DocumentationDetailComponent }]
  }
]; 
是说主路由器出口应该包含
DocumentPage
组件,这听起来像是在工作

也就是说,如果提供了一个id,那么只显示一个孩子

如果没有id,则需要显示默认路线

如果是这样,那么您需要以下内容:

children: [
  { path: ':id', component: DocumentationDetailComponent },
  { path: '', redirectTo: 'firstSteps', pathMatch: 'full' }
]

我不确定确切的语法,因为我不确定
firstSteps
在路由层次结构中的位置。但这样做应该行得通。

没错。如果没有id,我需要一个默认路由(在这种情况下,必须选择第一步)。我制作了一个图表,请看-->PD:左侧的菜单选项是动态的,因此我无法按照建议在路线定义中直接键入“第一步”。
children: [
  { path: ':id', component: DocumentationDetailComponent },
  { path: '', redirectTo: 'firstSteps', pathMatch: 'full' }
]