0

This is my current setup:

 - app (Folder)
  - app-routing.module.ts (File)
     - client (Folder)
         - client-routing.module.ts (File)
             - service (Folder)
                 - service-routing.module.ts (File)
                 - service1.componenent.ts (File)
                 - service2.componenent.ts (File)

So, right now if I use router.navigateByUrl inside service1.componenet I'll have to do it like this:

this.router.navigateByUrl('/client/service2');

I'll have to keep nesting routing-modules so knowing the "parents" of the route later on might be a problem, I wanted to know if there is a more efficient solution rather than copying the whole route, something like:

this.router.navigateByUrl( parentRoute + '/service2');

Where the parentRoute it's a compilation of the nested routes.

1 Answer 1

2

You could try using the ActivatedRoute in the service1component. Something like this:

import { Router, ActivatedRoute } from '@angular/router';

@Component({
...
})
export class Service1Component {
 constructor(
   private _router:Router,
   private _route: ActivatedRoute
 ){}

 ...

  navigate(){
    this._router.navigate(['./service2'],{
      relativeTo: this._route
    });
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.