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.