balteo
balteo

Reputation: 24659

Issue with angular2 router' resolve being executed twice

I have got an issue with my configuration of angular2 router's Routes whereby a resolve is executed twice although defined only once.

Here is my Routes definition:

export const AppRoutes: Routes = [
  {path: '', component: HomeComponent},
  {
    path: 'dashboard',
    component: DashboardComponent,
    children: [
      {
        path: '',
        component: DashboardSummaryComponent,
        resolve: {
          userAccount: UserAccountResolve
        }
      },
      ...

When I navigate to '/dashboard' as follows:

this.router.navigate(['/dashboard'])

The resolve for DashboardSummaryComponent (i.e. UserAccountResolve) is executed twice...

Can someone please explain why? Is this to be expected?

edit 1: It must be noted that UserAccountResolve is actually an http call. Also, the first call (the one that fails) results in a 401 error. (this seems to be irrelevant to the issue)

edit 2: The issue is probably related to the use of child components but I was not able to find relevant information in the angular 2 documentation about how resolves are dealt with by child/parent components...

Upvotes: 4

Views: 999

Answers (2)

Tzach Ovadia
Tzach Ovadia

Reputation: 1316

This issue is fixed in Angular 4.0

Upvotes: 1

Tzach Ovadia
Tzach Ovadia

Reputation: 1316

Could be related to Router 3.2.0 - Providers instantiated twice

Try downgrading @angular/router to ~3.1.0

Upvotes: 1

Related Questions