【发布时间】:2018-06-16 12:14:00
【问题描述】:
为我使用嵌套路由的原因是动态处理每个页面的图标和后退按钮。我有抽象路由,因为当我单击后退按钮时,路由参数消失,我放置了一个抽象路径以在 url 中保留 id 和问卷类型参数.我的抽象路径是问卷调查。
const routes: Routes = [
{
path: '',
component: LayoutComponent,
children:[
{ path: 'Home', component: HomeComponent,data:{icon:'fa-home'} },
{ path: 'QuestionaireList', component: QuestionaireListComponent,data:{icon:'fa-list-ul',previousState:'/Home'} },
{ path: 'ModifyMetaContent/:metaContentId/:title', component: ModifyMetaContentComponent,data:{icon:'fa-database',previousState:'/MetaContentList'}}
{
path: 'Questionaire/:id',
children:[
{ path: 'MetaContentList', component: MetaContentListComponent,data:{icon:'fa-database',previousState:'/QuestionaireList'}}
]},
{
path: 'Questionaire/:questionnaireType',
children:
[
{ path: 'AddQuestionnaire', component: CreateQuestionnaireComponent,data:{icon:'fa-plus',previousState:'/QuestionaireList'}},
]},
{
path: 'Questionaire/:questionnaireType/:id',
children:[
{ path: 'UpdateQuestionnaire', component: EditComponent,data:{icon:'fa-pencil',previousState:'/QuestionaireList'} },
{ path: 'QuestionList', component: QuestionListComponent,data:{icon:'fa-pencil',previousState:'/QuestionaireList'} },
{ path: 'ImportQuestion', component: ImportQuestionComponent,data:{icon:'fa-plus',previousState:'/QuestionaireList'} },
]} ,
]},
];
MetaContentList.Component.html
<a class="ui labeled positive icon small button" [routerLink]="['/ModifyMetaContent','',questionnaireTitle]">
<i class="plus icon"></i>
new metaContent
</a>
我将以前的网址存储在snapshot.data.previousState 中,但是当我点击ModifyMetaContent 时,我会转到
localhost:4200/ModifyMetaContent/...
当我单击返回按钮时,id 和 questionnairetype 从 url 中消失。当我单击 ModifyMetaContent 时,我希望转到:
localhost:4200/Questionaire/b8b55b42-f39f-4359-93d0-0260ddf3827f/MetaContentList/ModifyMetaContent/...
当我点击后退按钮时,我希望转到
.../Questionaire/b8b55b42-f39f-4359-93d0-0260ddf3827f/MetaContentList/ 但网址设置为 本地主机:4200/元内容列表
这个错误发生了:
无法匹配任何路线。 URL 段:'MetaContentList'
我通过 angularjs ui-router 的嵌套状态来处理这种情况。在 angular2+ 路由器中有什么解决方案吗?
【问题讨论】:
标签: angular router angular-router angular4-router