0

I am trying to figure out a better way to get (or combine for lack of better words) the route params from the parent component and the currently activated route.

Previously, I have been working with strictly child routes.

What I have is working, but I feel like I am reaching outside of the available tools. Specifically, when I'm subscribing to activatedRoute.parent!.params I don't think that this is actually a thing: this.activatedRoute.snapshot.params['resourceId']

Here is what my child component looks like. I'm passing in ActivatedRoute and using .parent to get the parent params.

// child.component.ts

constructor(private readonly activatedRoute: ActivatedRoute) {...}

ngOnInit(): void {
    this.activatedRoute.parent!.params.pipe(
                switchMap((params) =>
                    this.resourceService.getResource(
                        params['organizationId'],  // parent
                        params['locationId'],      // parent
                        this.activatedRoute.snapshot.params['resourceId'] // this seems gross
                    )
                )
            )
            .subscribe((response) => {
                //...
            });
    }

Here is what my routes look like. Im able to get the params from each route.

{
    path: 'settings/organizations/:organizationId/locations/:locationId',
    component: ParentComponent,
    children: [
        {
            path: 'resources/:resourceId',
            component: ChildComponent
        }
    ]
    ...
}

Is there a more effective way to "combine" route params that I can subscribe to?

Damon
  • 4,151
  • 13
  • 52
  • 108

0 Answers0