How to update data allowed by a route

Consider the following route configuration:

const routes: Routes = [ { path: '', component: AppComponent, resolve: { app: AppResolver }, children: [ { path: 'user/:uid', resolve: { user: UserResolver }, children: [ { path: '', component: ViewUserComponent }, { path: 'edit', component: EditUserComponent } ] } ] } ]; 

User data is retrieved by UserResolver for any children on the /user/:uid route. Using this data, the user profile can be viewed by going to /user/:uid , and then editing it by going to /user/:uid/edit . After successful editing, the updated user <<22>) could be redirected to the profile.

However, both the viewing page and the editing page are children of the allowed route, the converter does not start when switching from one to another.

Therefore, when moving from the editing component to the presentation component, the displayed data is still old, not updated.

Will there be any way to invalidate the allowed user data to force the resolver to retrieve it from the server again? Or is there any other way to achieve such a result?

The app data does not change, we do not need to reload it.

+5
source share
2 answers

I tested the solution "runGuardsAndResolvers", it works for my use case, the resolver is called on every subpage.

This only adds this parameter to the part of your routes that you want to lead in this way.

 export const ROUTES: any = [ { path: 'project/:name', runGuardsAndResolvers: "always", component: ProjectComponent, resolve: { project: ProjectResolver }, children: [ ... 
+5
source

In the route configuration, you can use the runGuardsAndResolvers parameter, which will affect the operation of the converter. In this case, you want to install it "always." This means that the converter will start at any time when the child routes of this route are changed. See the route documentation for more details.

+3
source

Source: https://habr.com/ru/post/1268308/


All Articles