1

Here is my code:

<span *ngIf="markup.baseline">   
   <mat-icon [routerLink]="['/default-markup', markup.id]">edit</mat-icon>
 </span>
 <span *ngIf="markup.baseline == 0">   
   <mat-icon [routerLink]="[markup.id]">edit</mat-icon>
 </span>

The first link where the url has to be 'default-markup/14' doesnt work. It works correctly for the second condition.

The error is

core.js:6014 ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'default-markup/14

Here is the code in the routing module:

      {path: ':client', component: MarkupsListComponent, },
      {path: ':client/default-markup', component: MarkupsBaselineComponent,},
      {path: ':client/default-markup/:rule_id', component: MarkupsBaselineComponent,},
      {path: ':client/:rule_id', component: MarkupsDetailComponent,},
4
  • what appears in the URL when you click [routerLink]="[markup.id]" link? Commented Nov 23, 2020 at 5:05
  • My current page url is markups/brookshuff. When I click on [markup.id], it goes to markups/brookshuff/12. I want that for the other condition it should go to markups/brookshuff/default-markup/14 Commented Nov 23, 2020 at 5:24
  • 1
    Just try removing / before default-markup. Try [routerLink]="['default-markup', markup.id]" Commented Nov 23, 2020 at 5:35
  • 1
    Added answer. Please check, thanks :) Commented Nov 23, 2020 at 6:43

2 Answers 2

2

You have to remove / before the /default-markup. When you mention / in the URL, it consider it from the root route, otherwise it will be relative to current route.

Use below

[routerLink]="['default-markup', markup.id]"
Sign up to request clarification or add additional context in comments.

Comments

1

you have to pass client id for every route change it like this,

<span *ngIf="markup.baseline">   
  <mat-icon [routerLink]="['/', clientId,'default-markup',markup.id]>edit</mat-icon>
</span>
<span *ngIf="markup.baseline == 0">   
  <mat-icon [routerLink]="[clientId]">edit</mat-icon>
</span>

stackblitz example

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.