I need to retrieve the routing URL of a component that is different from the current URL and save it in a service. For example, if my component is called parentComponent
and contains another component called childComponent
, then the URL of the child component would be
/parentComponent/childComponent
If I visit the above URL and use this.router.url
in the ngOnInit
method of the parentComponent
, it will correctly return /parentComponent/childComponent
. How can I retrieve just /parentComponent
, which is the route to the parent component itself, from the router within the parent component?