Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

119
Vistas
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 Respuestas
Responde la pregunta

0

Try it:

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

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda