In my parent controller, I have common requests and I also read router params for those requests. However, for the child components, I have different requests but still need to extract the same parameters from the router - resulting in duplicate code.
For both parents and children:
this.param1 = this.route.snapshot.paramMap.get('param1');
this.param2 = this.route.snapshot.paramMap.get('param2');
The initialization of param1 and param2 remains the same.
Children are used via
<router-outlet></router-outlet>
The connection between parent and children is done via Services.
Is there a better way to avoid this duplication? Perhaps moving the reading of params to a Service and subscribing to it? But then I still have to initialize the variables. Or maybe creating a common class and implementing it in both the parent and child components?