L.Wonbae
L.Wonbae

Reputation: 131

How to resolve chaning in Router of Angular4

I'm trying to chaining the router resolver

This is my Router options.

  { path: '',
    component: AdminComponent,
    resolve: [
      SessionResolve,
      LocaleResolve
    ]
  }

I want to call SessionService(SessionResolve) and then call LocaleService(LocaleResolve) with lang value of Session data

However, the above code calls resolve at the same time

I think resolve code changes here But i don't know because I have not used Angular4 before.

Is there a way I can use resolve as a chanining? Or should I handle all the work in one resolve?

Upvotes: 1

Views: 74

Answers (1)

Yakov Fain
Yakov Fain

Reputation: 12376

Resolve is one of the guards supported by the Angular router. If you have more than one guard, they are being executed asynchronously in no particular order.

If you need to maintain an order, create another class (e.g. SessionAndLocaleResolve) that implements the Resolve interface, and inside that class execute the function from the SessionResolve, and then from LocalResolve. This way your route will have one resolver SessionAndLocaleResolve and you can control the order of execution of "sub resolvers".

Upvotes: 1

Related Questions