首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >重新加载Angular子组件会将用户带到localhost:4200

重新加载Angular子组件会将用户带到localhost:4200
EN

Stack Overflow用户
提问于 2020-01-24 21:11:54
回答 1查看 59关注 0票数 2

在我的Angular应用程序中,我有一些子组件可以接受路由参数。我可以很容易地从父组件重定向到这些子组件,但是当我重新加载子组件时,应用程序导航到localhost:4200并给出如下路由错误。

代码语言:javascript
复制
Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'project-setup/project-setup-steppers'

以下是我的路由配置:

代码语言:javascript
复制
const routes: Routes = [
  { path: 'dashboard', component: DashboardComponent, canActivate: [AuthenticationGuardService] },
  { path: 'project-setup', component: ProjectSetupComponent, canActivate: [AuthenticationGuardService] ,
    children: [
    {
      path: 'project-setup-steppers/:projectId',
      component: ProjectSetupSteppersComponent,
      canActivate: [AuthenticationGuardService]
    },
    {
      path: 'selfs', component: SelfsComponent, canActivate: [AuthenticationGuardService],
      children: [
        {
          path: 'raters/:selfUserId/:formSetUpKey',
          component: RatersComponent, canActivate: [AuthenticationGuardService]
        }
      ]
    },
  ]},
  { path: 'participant-setup', component: ParticipantSetupComponent, canActivate: [AuthenticationGuardService] },
  { path: 'launch-and-status', component: LaunchStatusComponent, canActivate: [AuthenticationGuardService] },
  { path: 'launch-project-desc', component: LaunchProjectDescriptionComponent, canActivate: [AuthenticationGuardService] },
  { path: 'question-setup', component: QuestionSetupComponent, canActivate: [AuthenticationGuardService] },
  { path: 'email-setup', component: EmailSetupComponent, canActivate: [AuthenticationGuardService] },
  { path: 'participant-steppers', component: ParticipantSteppersComponent, canActivate: [AuthenticationGuardService], children: [] },
  {
    path: 'report-project-list', component: ReportProjectListComponent, canActivate: [AuthenticationGuardService],
    children: [
      {
        path: 'report-project-detail-list/:projectId',
        component: ReportProjectDetailListComponent, canActivate: [AuthenticationGuardService]
      }
    ]
  },

  { path: 'report-detail/:id/:type', component: ReportDetailComponent, canActivate: [AuthenticationGuardService] },
  { path: 'trial/:projectId', component: TrailRunProjectComponent, canActivate: [AuthenticationGuardService] },
  { path: 'status-of-project/:projectId', component: StatusOfProjectComponent, canActivate: [AuthenticationGuardService] },
  { path: 'project-status-details', component: ProjectStatusDetailsComponent, canActivate: [AuthenticationGuardService] },
  { path: 'news', component: NewsComponent, canActivate: [AuthenticationGuardService] },
  { path: 'view-responses/:assigneeId', component: ViewProjectResponsesComponent, canActivate: [AuthenticationGuardService] },
  { path: 'copy-project/:projectId', component: CopyProjectComponent, canActivate: [AuthenticationGuardService] }

];

我在父组件中使用嵌套router-outlet来渲染子组件。即使用户从子组件重新加载应用程序,我也希望保持相同的路线。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-01-24 21:28:15

将其添加到您的应用程序路由文件中

代码语言:javascript
复制
      ...
      },
      {
        path: 'report-project-detail-list',
        component: ReportProjectDetailListComponent, canActivate: [AuthenticationGuardService]
      }

如果需要可选参数,您必须定义带参数和不带参数的路由。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59897150

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档