2

I have two route:

{path: 'route1',component: component1,resolve: {parameters: resolver1}}
{path: 'route2',component: component2,resolve: {parameters: resolver2}}

I navigate from route1 to route2 , the route2's resolver react before Ondestroy route1 , is it logical ?

My issue is that, if I call a service on resolver2 which update an object1 bound with an observable on the page1 all observable's object1 on this page1 will react .

I find that weird because we leave the page . Furthermore , if requests of service are present in the Observable they also react and so we have too much request's service .

Aaqib
  • 9,942
  • 4
  • 21
  • 30

1 Answers1

1

Yes, it is completely logical. What is a resolver? It is a piece of code that makes sure that some initial data is loaded before a route is initialized and the component is loaded, so, for example, a user is not presented with a blank page if data load fails and remains on the previous page. You can think of it like this: when you start navigation, if there are any resolvers, they will run, and if (and only if) the data is successfully loaded, the previous component will be destroyed (thus invoking ngOnDestroy) and replaced with a new one, so yes, this is not only completely logical, but actually the only proper way to implement such behavior. You can read more about resolvers here

Armen Vardanyan
  • 3,214
  • 1
  • 13
  • 34