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

117
Views
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 answers
Answer question

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 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!