【发布时间】:2018-09-23 18:38:00
【问题描述】:
我在结构中有一系列Angular组件如下。
- RootComponent --> 包含路由器出口
- 子组件->
包含路由器插座
- 大子组件 -> 包含一个按钮以触发返回根组件的导航
- 子组件->
包含路由器插座
我的问题来自孙组件中按钮上的 routerLink 我如何导航到根组件?
应用程序路由
const routes: Routes = [
{
path: '',
redirectTo: environment.devRedirect,
pathMatch: 'full',
canActivate: [AuthenticationGuard]
},
{
path: 'customers/:customerId/contracts/:contractId',
canActivate: [AuthenticationGuard],
children: [
{
path: 'projects/:projectId/grouping',
loadChildren: './grouping/grouping-routing.module#GroupingRoutingModule',
data: { animation: 'grouping' },
canActivate: [ AuthenticationGuard ]
},
{
path: '',
loadChildren: './projects/projects-routing.module#ProjectOverviewRoutingModule',
data: {
animation: 'project-overview'
},
canActivate: [ AuthenticationGuard ],
},
]
}
];
子组件路由
const routes: Routes = [
{
path: '',
component: GroupingComponent,
canActivate: [ AuthenticationGuard ],
children: [
{
path: 'create',
component: CreateEditComponent,
data: { animation: 'create' },
canActivate: [ AuthenticationGuard ]
},
{
path: ':groupId/edit',
component: CreateEditComponent,
data: { animation: 'edit' },
canActivate: [ AuthenticationGuard ]
},
{
path: '',
component: OverviewComponent,
data: { animation: 'overview' },
canActivate: [ AuthenticationGuard ]
}
]
}
];
【问题讨论】:
-
按钮上的 routerLink="/" 不起作用吗?
-
显而易见的解决方法是使用输出将点击发送回父组件,并从那里处理路由。
标签: angular typescript angular5 angular-router