Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Unable to fetch ID param for child routes #437

Open
rupamroy opened this issue Feb 26, 2018 · 0 comments
Open

Unable to fetch ID param for child routes #437

rupamroy opened this issue Feb 26, 2018 · 0 comments

Comments

@rupamroy
Copy link

I have a web-module which has a the following routes defined among many of the rest. I have deleted the rest of the routes below apart from the dashboard and the repository-targets to show the issue.

const routes: Routes = [
  {
    path: '', redirectTo: 'web', pathMatch: 'full'
  },
  {
    path: 'web', component: WebComponent,
    children: [
      {
        path: '', redirectTo: 'dashboard', pathMatch: 'full'
      },
      {
        path: 'dashboard', component: DashboardComponent, canActivate: [SiteminderLoginGuard], data: {
          destinationRoute: 'web/dashboard'
        }
      },
      {
        path: 'repository-targets/:id', component: RepositoryTargetsComponent,
        children: [
          {
            path: '', redirectTo: 'list', pathMatch: 'full'
          },
          {
            path: 'list', component: TargetsComponent,  canActivate: [SiteminderLoginGuard], data: {
              destinationRoute: 'web/repositories'
            }
          },
          {
            path: 'target', component: EditTargetComponent,
              canActivate: [SiteminderLoginGuard], data: {
              destinationRoute: 'web/repositories'
            }
          }
        ]
      }
    ]
  }
];

Now web is a component which has a where dashboard and repository-targets components are displayed.

Now repository-targets component is having a where the TargetsComponent is displayed.

So when i am viewing the TargetsComponent the url link is
http://localhost:9000/web/repository-targets/2022/list

In the TargetsComponent if i try to fetch the repositoryID like this

this.route.params.subscribe((val) => {
      if (val.id) {
        this.repositoryId = val.id;
      } else {
        throw Error('Cannot fetch repository Id from route');
      }
    });

Here it cannot fetch the val.id and throws and error.

Can you kindly let me know why is this happening.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant