Typically, calling a method on another component from the router is not the recommended approach. Instead, it's better to provide the necessary information from the component initiating the navigation and then retrieve it in the landing component by injecting the router.
There are two common solutions using the router:
- Include the desired information as part of the route and retrieve it using
ActivatedRoute
in the landing component. More details can be found here.
- Utilize query parameters to pass information when navigating to other routes and then retrieve it using
ActivatedRoute
in the landing component. Additional information can be found here.
Alternatively, you can centrally store data within your application and subscribe to changes in the components that require this data. Two methods for achieving this include:
- Create a service with an Rxjs Subject to manage data updates and subscribe to these changes in the landing component.
- Implement a state management solution like NGRX or NGXS, dispatch actions to update selected elements, and retrieve information from the store in the landing component.
Based on the provided information, either option 1) or 2) would be suitable for your use case, depending on whether the information should be included in the route or as a query parameter.