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

118
Vistas
Asynchronous condition in Angular routing

I am using Angular and I depending of an asynchronous function (foo(): Promise<boolean>) I want to show either component Foo or Bar.

What would be the best approach for this? I don't think route guards are the best fit for my requirement.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Well, it depends where you are executing foo() function. Generally yes, you can do it with Route Guards, but you can also do it in TypeScript file of the Component where the foo() function is executed.

import { Router } from '@angular/router';

...

constructor(private router: Router) { }

...

navigateToComponent = async () => {
  try{
    result = await foo();
    if(result == 'Foo') this.router.navigate(['/Foo']);
    if(result == 'Bar') this.router.navigate(['/Bar']);
  } catch(error) {
    console.log('ERROR: ', error);
  } 
}

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