将路由重定向到同级组件不起作用

时间:2018-10-15 05:24:39

标签: angular angular-routing

这是我的路线,

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中有一个提交后退按钮。

  1. 如果用户按下“提交”,则需要将其重定向到answer-overview

  2. 如果用户按下,我需要将其重定向到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添加到该字符串并进行导航。但是,没有这个,还有什么更好的解决方案。

0 个答案:

没有答案