angular - 角度改变子路径
问题描述
我是 Angular 的新手,所以这对某些人来说似乎是一个显而易见的问题,但我似乎找不到答案。我创建了一些这样的路线:
const routes: Routes = [
{
path: 'steps', children: [
{
path: 'one', component: OneComponent, children: [
{
path: 'two', component: TwoComponent, children: [
{
path: 'three', component: ThreeComponent, children: [
{ path: 'results', component: ResultsComponent }
]
}
]
}
]
}
]
}
];
我创建了一组按钮来导航这些视图:
<a class="btn btn-primary" [routerLink]="['home']" [routerLinkActive]="['active']">Home</a>
<a class="btn btn-primary" [routerLink]="['/steps', 'one']" [routerLinkActive]="['active']">One</a>
<a class="btn btn-primary" [routerLink]="['/steps', 'one', 'two']" [routerLinkActive]="['active']">Two</a>
<a class="btn btn-primary" [routerLink]="['/steps', 'one', 'two', 'three']" [routerLinkActive]="['active']">Three</a>
<a class="btn btn-primary" [routerLink]="['/steps', 'one', 'two', 'three', 'results']" [routerLinkActive]="['active']">Results</a>
他们正在按预期工作。我唯一的问题是网址。它们如下:
- /步骤/一个
- /步骤/一/二
- /步骤/一/二/三
- /步骤/一/二/三/结果
我希望他们是:
- /步骤/一个
- /步骤/二
- /步骤/三
- /步骤/结果
但工作方式与他们目前的工作方式完全相同。这可以做到吗?
解决方案
const routes: Routes = [
{
path: 'steps', children: [
{ path: 'one', component: OneComponent},
{
path: 'two', component: OneComponent, children: [
{
path: '', component: TwoComponent
}
]
},
{
path: 'three', component: OneComponent, children: [
{
path: '', component: TwoComponent, children: [
{
path: '', component: ThreeComponent
}
]
}
]
},
{
path: 'results', component: OneComponent, children: [
{
path: '', component: TwoComponent, children: [
{
path: '', component: ThreeComponent, children: [
{ path: '', component: ResultsComponent }
]
}
]
}
]
}
]
}
];
推荐阅读
- spring - 为什么应用程序/json获取请求上的Spring解码+(加号)?我该怎么办?
- c# - 带有 API 密钥的广告系列监控帖子
- android - 为什么我的字段在注入后是“空”?如何注入我的对象?
- unix - 如何替换文本文件中每出现一次的单词
- android - Android @SuppressWarnings 在语句级别,而不是方法级别
- angular - 离子日期时间绑定到纪元
- ios - 从 iPhone 触发 Apple Watch 应用程序启动
- android - 使用带有 POP3 或 IMAPS 协议的 javamail 检索所有 uread 电子邮件
- openstack - 如何使用 svirt 保护虚拟机管理程序?
- javascript - 如何使表单具有响应性