I am currently facing an issue where I want to go back to the parent URL when a specific option is changed and there are additional route parameters, but maintain the current URL if there are no route parameters.
To better illustrate this problem, let me provide you with an example.
Consider that I have 3 components: CompA, CompB, and CompC, each containing a list of items. When navigating to any of these components, the URL reflects either /compA, /compB, or /compC.
It is also possible to navigate within each component to a specific item, represented in the URL as /compA/item1.
My goal is to have a dropdown menu to select a particular client and then based on whether route parameters are present, either navigate back to the parent or retain the current route.
For instance, if I am on /compA/item2 and change the client, I expect to be redirected to /compA. On the other hand, if I'm on /compB and switch clients, I should stay on /compB.
Although I attempted using the following code snippet:
this.router.navigate(['.'], { relativeTo: this.activeRoute.parent });
it did not work as expected for me.