Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

120
Views
How to pass a mixture of string and variable into routerLink for navigation?

I'm helping implement localization in an angular web application using a language switcher that I implemented using transloco. The way transloco works is that it adds the two digit language code /en/ right after the domain in the URL, and the end point and sub location just follows after the language code. This was the old code that worked fine before I implemented localization:

  <div class="navbar-brand">
    <ng-container *ngIf="sites$ | async as sites">
      <a [matMenuTriggerFor]="menu" href="javascript:void(0);">{{ siteName$ | async }}</a>
      <mat-menu #menu="matMenu">
        <button *ngIf="admin$ | async" mat-menu-item routerLink="admin">Admin</button>
        <button *ngFor="let site of sites" mat-menu-item [routerLink]="site.id">{{ site.name }}</button>
      </mat-menu>
    </ng-container>
  </div>

So in order to go to the right page as soon as the app loads, I had to change "admin" to "en/admin" instead. However site.id is a variable, so how do I pass in the string value inside site.id inside the router link value. This is what I tried, but it obviously doesn't work properly:

  <div class="navbar-brand">
    <ng-container *ngIf="sites$ | async as sites">
      <a [matMenuTriggerFor]="menu" href="javascript:void(0);">{{ siteName$ | async }}</a>
      <mat-menu #menu="matMenu">
        <button *ngIf="admin$ | async" mat-menu-item routerLink="en/admin">Admin</button>
        <button *ngFor="let site of sites" mat-menu-item [routerLink]="'en' + /site.id">{{ site.name }}</button>
      </mat-menu>
    </ng-container>
  </div>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Try it:

[routerLink]="'en/'+site.id"

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!