2

Here is my simplified routes for angular2 project:

export const ROUTES: Routes = [
  {
    path: "user/:user_id",
    component: UserAuthComponent,
    resolve: {
      _auth: UserAuthResolver
    },
    children: [
      {
        path: "",
        component: UserComponent,
        resolve: {
          user: UserResolver
        }
      },
      // .... many more routes that require authentication cookie 
    ]
  }
]

where UserAuthResolver makes GET request to server to set authentication cookie (which is required for UserResolver as well as all children routes resolver (not shown here) to succeed).

But it seems that angular2 doesn't sequentially execute the resolve in parent route and resolve in children routes but instead, it races all the 'relevant' resolve. Therefore, very often, the above code will alert authentication errors.

Is there a way to work around this?

FYI, I cannot put UserAuthResolver, say, inside UserComponent because then, it means duplicating the 'authentication' code all over the places where it is required.


Edit: This thing is apprently called, nested resolve. In short, how do I deal with nested resolve in angular2? In Angular1, it seemed possible.

Community
  • 1
  • 1
Daniel Shin
  • 5,086
  • 2
  • 30
  • 53
  • [This question](http://stackoverflow.com/questions/39364815/angular-2-nested-routes-resolve-execution) seems related, but no answer is given... – Daniel Shin Oct 13 '16 at 02:34

1 Answers1

2

Apparently, this was a known bug and is fixed in new 2.1.0 release.

I've confirmed that this release indeed solves the issue.

Daniel Shin
  • 5,086
  • 2
  • 30
  • 53