I'm facing an issue with my angular application where I have two pages - one with a form and the other with data. Upon clicking a button, I navigate to the results page using router.navigate. However, I've noticed that sometimes the navigation doesn't work on the first click. I have to click the button twice to successfully navigate. I even tried using a timeout in the function, but it's not consistent. Here's the code snippet using Router from Angular:
public goToResults() {
if (this.form.valid) {
setTimeout(() =>
this.router.navigate(["resultados/es"])
, 500);
}
else {
this.showErrors = true;
}
}
Here's the app.routes file:
export const routes: Routes = [
{ path: 'datos/:lang', component: UserDataComponent },
{ path: 'resultados/:lang', component: ResultsComponent, canActivate: [ReloadGuardService] },
{ path: '**', redirectTo: '/datos/es', pathMatch: 'full' }
];
I've debugged the code and confirmed that it enters the timeout and executes the navigate line, but the issue still persists randomly. There are no errors in the console either. Can anyone help me figure out what's wrong? Thank you.