Get parameter from parent route (router-lite)

Is it possible to get route parameters from parent in a child route (router-lite)?

Thanks for any help!

Hi @elitastic! In your example, you are already passing the id as a route parameter to the employee-info, and as I see here, those parameters are read correctly as well. You can see that here: parameters from parent (forked) - StackBlitz.

However, I feel that you are looking for a way to avoid having the :idroute parameter for the info route, because it produces /employee/1/info/1, which might be aesthetically displeasing. If that’s what bothering you, then you might choose to inject the IRouteContext and grab the parameter from the parent node. A hasty example looks like below.

import { resolve } from '@aurelia/kernel';
import { IRouteContext } from '@aurelia/router-lite';

export class EmployeeInfo {
  private readonly id: string = resolve(IRouteContext).parent.node.params.id;
}
2 Likes

Perfect, thanks for your help!

1 Like