【发布时间】:2016-10-26 11:09:26
【问题描述】:
我想在我的应用程序中有以下路由:
export const routes: Routes = [
{
path: ':universityId',
component: UniversityComponent,
children: [
{ path: 'info', component: UniversityInfoComponent },
{ path: 'courses/:status', component: CoursesByStatusComponent }
]
}
]
在/1/info 或/1/courses/open url 上,我如何仅从UniversityComponent 更改:universityId?
简单的router.navigate(['../', 2], {relativeTo: currentRoute }) 不会这样做,因为它会重定向到/2,从而丢失所有其他信息。使用'../2/courses/open 也不是一种选择——那时我可以在任何子路线上。
我能想到的最好办法是:
const urlTree = this.router.parseUrl(this.router.url);
urlTree.root.children['primary'].segments[0].path = '2';
this.router.navigateByUrl(urlTree);
但是有点丑
【问题讨论】:
-
您找到答案了吗?我也有兴趣知道。
-
@GünterZöchbauer 为什么没有回答这个问题? :)
-
@sabithpocker 没有那么多时间了:-/
-
@GünterZöchbauer 很酷,对你有好处。您的回答非常很有用。你有点回答了我搜索的每一个问题:P
-
很高兴听到。我希望你喜欢 Angular :)