AshKeys

Confessions and Confusions of a Freelance Fullstacker.

Ashok Mannolu Arunachalam, How toAngularRouting
Back

How to relatively route in Angular

Routing in Angular is interesting enough already, it becomes tricky when you want to route to a relative path. For instance, if we are here projects/project looking at the project details and want to route to the project team's information (projects/project/team).

We do not have to give the entire URL instead, we can do the following.

ts
import { Router, ActivatedRoute } from '@angular/router';
constructor(
private readonly router: Router,
private readonly activatedRoute: ActivatedRoute
) { }
this.router.navigate(
['team'], { relativeTo: this.activatedRoute }
);