I do have angular 10 application and added routing resolver for one of its competent. When I navigate to the resolver added component via different service, observed that routing resolver is calling twice for each request (problem is not the routing resolver is not working, but its executing twice per request)
customer-resolver.ts
@Injectable({
providedIn: 'root'
})
export class CustomerResolver implements Resolve<any> {
constructor(
private serviceApi: ApiService,
private stateService: StateService
) { }
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise<any> {
return this.persistToState();
}
private async persistToState(): Promise<void> {
let custId = this.stateService.custId;
const data = await this.serviceApi.getCustomerData(custId);
this.stateService.customerData = data;
}
}
app-routing.module.ts
const routes: Routes = [
{ ... },
{
path: "customer",
component: CustomerComponent,
canActivate: [CanActivateCustomer],
resolve: { cust: CustomerResolver }
},
{ ... }
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
Any hint why routing resolver get execute twice ?