这是我的路线,
export const MY_ACCOUNTS_ROUTES: Routes = [
{
path: 'my-accounts',
component: MyAccountsPage,
canActivate: [LoginGuard]
},
...environment.features.accounts.myAccountsDetails ? [{
path: 'my-accounts/:id',
component: AccountDetailsPage, children: [
{ path: '', redirectTo: 'overview', pathMatch: 'full' },
{ path: 'overview', component: OverviewComponent },
{ path: 'history', component: HistoryComponent },
{ path: 'details', component: DetailsComponent },
{ path: 'user-management', component: UserManagementComponent },
{
path: 'requirement-from-authorities',
component: RequirementFromAuthoritiesComponent,
children: [
{ path: '', redirectTo: 'owner-list', pathMatch: 'full' },
{ path: 'owner-list', component: OwnerListComponent },
{ path: 'questions/:id', component: PepQuestionComponent },
{ path: 'answer-overview', component: AnswerOverviewComponent }
]
},
]
}] : [],
];
我正在RequirementFromAuthoritiesComponent
下创建组件。
像这样,我从OwnerListComponent
重定向到PepQuestionComponent
this.router.navigate(['../questions', owners[0].OwnerId], {relativeTo: this.route})
那很好。
但是现在我在PepQuestionComponent
中有一个提交和后退按钮。
如果用户按下“提交”,则需要将其重定向到answer-overview
如果用户按下,我需要将其重定向到owner-list
我的网址是
http://localhost:4200/en/accounts/my-accounts/16599/requirement-from-authorities/questions/1
我尝试过
this.router.navigate(['../answer-overview',], {relativeTo: this.route})
它不起作用。只是将参数1
替换为answer-overview
,而不是替换完整的questions/1
并创建类似http://localhost:4200/en/accounts/my-accounts/16599/requirement-from-authorities/questions/answer-overview
的URL
但是我需要
http://localhost:4200/en/accounts/my-accounts/16599/requirement-from-authorities/answer-overview
我可以解析该字符串并删除requirement-from-authorities
之后的所有内容,并将answer-overview
添加到该字符串并进行导航。但是,没有这个,还有什么更好的解决方案。