Reputation: 389
I am trying to substitute an anchor tag with a button tag to navigate to another route. As a result, I have a function that is called on click, which looks something like this:
submitReport (simpleOrDetailed : string) {
this.router.navigate(['../ticket-list', simpleOrDetailed]);
}
I used to have it like this embedded in the HTML and it worked perfectly fine:
<a class="btn btn-danger" [routerLink]="['../ticket-list', 'simple']" routerLinkActive="active"> Simple Report</a>
What's going on here? From my understanding, it should be doing the exact same thing.
UPDATE
I got it to match my route by replacing the body of the function with this (web-report is the parent component of the current component as well as the ticket-list component):
this.router.navigate(['web-report/ticket-list', simpleOrDetailed]);
However, this causes an unpleasant page reload.
Upvotes: 2
Views: 384
Reputation: 658077
If you do relative navigation you need to add relativeTo
this.router.navigate([crisis.id], { relativeTo: this.route });
https://angular.io/docs/ts/latest/guide/router.html
Upvotes: 1