【问题标题】:angular4 route issue by adding '%2f' character before path通过在路径前添加 '%2f' 字符来解决 angular4 路由问题
【发布时间】:2018-06-13 06:50:53
【问题描述】:

为我使用嵌套路由的原因是动态处理每个页面的图标和后退按钮。我有抽象路由,因为当我单击后退按钮时路由参数消失,我放置了一个抽象路径来保留 idquestionnaire url.my 抽象路径中的类型参数是Questionaire

 { path: 'Home', component: HomeComponent,data:{icon:'fa-home'} },
 { path: 'QuestionaireList', component: QuestionaireListComponent,data:{icon:'fa-list-ul',previousState:'/Home'} },
 { 
      path: 'Questionaire/:questionnaireType/:id',
      children:[ 
      { path: 'AddQuestionnaire', component: CreateQuestionnaireComponent,data:{icon:'fa-plus',previousState:'/QuestionaireList'} },
      { 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'}  },
      { path: 'MetaContentList', component: MetaContentListComponent,data:{icon:'fa-database',previousState:'/QuestionaireList'} },
      { path: 'ModifyMetaContent/:metaContentId/:title', component: ModifyMetaContentComponent,data:{icon:'fa-database',previousState:'/MetaContentList'}},
    ]}

同样在questionnaire.list.html我通过routerlink链接到每条路径 下面是我的链接之一:

[routerLink]="['/Questionaire',item.questionnaireType,item.id,'/UpdateQuestionnaire']"

这是我的链接:

 <a  class="primary small ui icon button" [routerLink]="['/Questionaire',item.questionnaireType,item.id,'/UpdateQuestionnaire']" >
                <i class="edit   icon"></i>
              </a>

我希望当我点击链接时我会路由到这个地址:

.../Questionaire/1/b8b55b42-f39f-4359-93d0-0260ddf3827f/UpdateQuestionnaire

但是发生了这个错误

无法匹配任何路线。网址段: '问卷/1/b8b55b42-f39f-4359-93d0-0260ddf3827f/%2FUpdateQuestionnaire'

实际上 routerlink 在 UpdateQuestionnaire 之前添加 %2f。 为什么会这样? 我的代码有什么问题

【问题讨论】:

    标签: angular angular2-routing angular-router angular4-router


    【解决方案1】:

    您是否尝试过像这样删除路由器链接中的斜线:

    [routerLink]=['Questionaire', item.questionnaireType, item.id, 'UpdateQuestionnaire']?

    post 中所述,routerlink 中的斜线似乎存在问题

    我会将此作为评论发布,但由于我没有足够的声誉,我会将其发布为答案,对此感到抱歉。

    我希望这可以为您解决问题。

    克里斯的问候

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-04
      • 1970-01-01
      • 2012-08-31
      • 2019-10-24
      • 2016-08-04
      • 2011-03-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多