angular - Angular路由器导航到父节点
问题描述
鉴于此路径树:
const routes: Routes = [
{
path: 'admin',
children: [
{ path: '', component: AdminComponent },
{
path: 'course',
children: [
{
path: 'manage/:_id',
children: [
{
path: '', component: CourseComponent,
},
{
path: 'unit/:unitId',
children: [{
path: '',
component: UnitComponent,
}]
}]
},
]
},
]
},
];
从以下传统导航方式导航admin/course/manage/1/unit/1
到父管理/:id 都不起作用。
<a routerLink="../../">router link Back</a>
<button (click)="back()">Imperative Back</button>
protected back() {
this.router.navigate(['../../'], { relativeTo: this.route, fragment: 'coolFrag' });
}
这是一个StackBlitz
解决方案
由于您在''
路线的子路径上,unit/:unitId
我会假设这是因为您的路径在路线中是空的。
与父路径节点相关而不是当前的空节点将使这对您有用
this.router.navigate(['../../'], { relativeTo: this.route.parent, fragment: 'coolFrag' });
推荐阅读
- sonata-admin - 在 SonataAdminBundle 的表单中添加 Order by 选项(在 Symfony 4 中)
- javascript - 有什么方法可以防止出站链接被本机应用程序处理?
- angular - 如何将模块导入子模块?
- teamcity - Katalon Studio 与 TeamCity 集成 - 错误 - com.kms.katalon.execution.exception.InvalidConsoleArgumentException:未找到测试套件“测试”
- c# - DevExpress XAF - 在 ViewController 中执行代码之前测试对象是否已注册
- java - Java JAXB 编组到 DOM 文档中
- python - CrawlerProcess / 不带任何物品 / Scrapy
- bash - BASH - 在另一个脚本中使用输出的最佳实践
- exception-handling - 如何处理 Modbus 异常 0x5
- swift - 使用 NSKeyedArchiver archivedData 将数据写入具有路径的文件会抛出 Unrecognized Selector for Swift 4.2