angular - 如何通过 URL 导航加载子路由?
问题描述
我有一条儿童路线。我试图路由到这条子路由,但没有成功。如果我将这条路线放在子数组之外(作为独立路线),那么它可以工作,但不在子数组中。路由器出口标签也在父 HTML 模板中。我究竟做错了什么?
{path:'adminpanel',component:AdminPanelComponent,canActivate:[AuthGuard],data :{permittedRoles:['Admin']},
children:[
//it des not work here
{path:'specific-role-section/:roleId' , component:SpecificRoleSectionComponent}
]},
//it works here
// {path:'specific-role-section/:roleId' , component:SpecificRoleSectionComponent}
//the caller method
openRoleSection(roleId:string)
{
// this.router.navigateByUrl(`specific-role-section/${roleId}` , {relativeTo: this.activatedRoute})
this.router.navigate([`specific-role-section/${roleId}`] , {relativeTo: this.activatedRoute})
}
解决方案
问题似乎出在您的调用者方法上。修改如下导航方法。
//the caller method
openRoleSection(roleId:string)
{
// Try this way
this.router.navigateByUrl(`adminpanel/specific-role-section/${roleId}` , {relativeTo: this.activatedRoute});
this.router.navigate([`adminpanel/specific-role-section/${roleId}`] , {relativeTo: this.activatedRoute})
}
推荐阅读
- flutter - 我在颤振中使用 ScreenUtil 库时出错
- javascript - 从 JavaScript 中的 CSS 颜色模式字符串更改多个实体的 Alpha 通道值
- kubernetes - Kubernetes 上的 Prometheus Presto-Exporter 配置
- c# - 为什么在 WPF 中使用页面时控件会变大?我该如何解决?
- vue.js - 使用 SVG 创建动态 Google 地图标记
- postgresql - 数组:找不到数据类型字符变化 [] 的数组类型
- python - 如何按某个值创建一列升序数字?
- android - Android Studio 上参数化类的原始使用
- python-3.x - Python Protobuf (IPv4/IPv6 地址) 到 Clickhouse FixedString(16)
- powershell - 使用 Powershell PNP 获取 Sharepoint 在线文档库中特定文件夹中的项目