Skip to content

Ability to manually trigger all resolvers on route change #31843

Closed

Description

@DanKing123

I have seen quite a few tickets related to this on github, and quite a few posts on this topic involving various workarounds elsewhere on the internet, e.g. on Stack Overflow, but there still doesn't seem to be a proper, simple solution for this included within the framework.

This is my use case:

  1. I have 2 routes with components - A & B - which share a common parent root (C).
  2. I have a resolver configured on C. A & B both share the data from this resolver
  3. In component A, I am performing a server update of the shared data, before navigating to route B.
  4. When performing this navigation, I want to force the resolver on C to fire again, so that B can see the latest version of the data that has just been modified by A.

Just to be clear:

  1. I do not want the resolver on C to fire every time I navigate between child routes of C, and I definitely don't want all my other resolvers firing every time I navigate between child routes. So onSameUrlNavigation is too course a solution for this use case.
  2. I want to be able to force all the resolvers to fire programatically, at the point of navigation, in specific situations as required - i.e. when I have just performed a server update and the route state has not yet been refreshed.

So I am looking for a parameter, or configuration option, that can be passed to Router.navigate() or navigateByUrl() that will force all the resolvers (and probably the guards) in the target route (hierarchy) to be re-executed.

E.g. something like the reload: true option provided in the AngularJS UI router, see here: https://ui-router.github.io/ng1/docs/latest/interfaces/transition.transitionoptions.html#reload - although I believe that also causes all the components to be destroyed and re-created, which is probably not necessary in this case.

Activity

  1. added this to the needsTriage milestone on Jul 25, 2019
  2. added
    feature
    on Aug 8, 2019
  3. modified the milestones: needsTriage, Backlog on Aug 8, 2019
  4. ctaylor-osv commented on Mar 9, 2020

    @ctaylor-osv

    This issue and #24096 are essentially the same - both are looking for a way to invalidate data from a resolver so that the next time a route is visited, the resolver re-loads the data.

    We are in need of this functionality too. Minimally, it would be nice to be able to pass a string or array of strings in NavigationExtras where the strings are keys of resolved data to invalidate/re-run resolvers for.

  5. angular-robot commented on Jun 4, 2021

    @angular-robot
    Contributor

    Just a heads up that we kicked off a community voting process for your feature request. There are 20 days until the voting process ends.

    Find more details about Angular's feature request process in our documentation.

  6. angular-robot commented on Jun 24, 2021

    @angular-robot
    Contributor

    Thank you for submitting your feature request! Looks like during the polling process it didn't collect a sufficient number of votes to move to the next stage.

    We want to keep Angular rich and ergonomic and at the same time be mindful about its scope and learning journey. If you think your request could live outside Angular's scope, we'd encourage you to collaborate with the community on publishing it as an open source package.

    You can find more details about the feature request process in our documentation.

  7. noguespi commented on Jan 13, 2023

    @noguespi

    Something similar to the recent onSameNavigationUrl PR #48050 merged in angular 15.1 would be perfect.

    For example by adding a {onSameNavigation: 'reload-all'} parameter.

    Retriggering/updating resolvers on the same route is definitely something we want to do occasionally and not every time (that's why the custom RunGuardsAndResolvers on the route is not ideal at the moment and having the ability to do it occasionaly on router.navigate is perfect).

    The hack I use to force reload parent resolvers when the route doesn't change is to use a custom RunGuardsAndResolvers which detect if there is a _nonce= query parameters in the URL and return true if detected.

    When I want to reload the resolvers, I just router.navigate([], {queryParams: { _nonce: new Date().getTime()}})

  8. Erbenos commented on Jan 14, 2024

    @Erbenos
    Contributor

    Technically this is already possible even without leaking stuff into query params (or any other user observable state) like @noguespi 's solution does, by using the custom route state specified at navigation time. (eg.: <a routerLink="a" [state]="{ a: true }">Navigate to "a" with resolver refresh</a>) and custom runGuardsAndResolvers strategy.

    There is couple of issues which make this not very nice however.

    • To read the state passed with navigation, one needs to obtain the current navigation from the Router instance as the custom runGuardsAndResolvers strategy only receives the from/to ActivateRouteSnapshot which does not include the state information and the strategy itself does not run within DI context so you can't use inject function to resolve the Router. To workaround this you can save the reference to injector at the app startup, eg.: using APP_INITIALIZER.
    • Its hard to compose with existing 'pathParamsChange' | 'pathParamsOrQueryParamsChange' | 'paramsChange' | 'paramsOrQueryParamsChange' | 'always' strategies as their implementation is not exported by the @angular/router so at best you either reimplement them or copy/paste the code into your codebase.

    Demo in stackblitz: https://stackblitz.com/edit/stackblitz-starters-yx7d9d?file=src%2Fmain.ts

  9. 3 remaining items

  10. mlpepper commented on Apr 6, 2024

    @mlpepper

    Is there any update on the state of this?

    Would love the ability to refetch a resolver from a child component. e.g.,

    Run the resolver on /users/:id from the child route /users/:id/details after a trigger has been executed. This will then allow the child details route and any others under /users/:id to get the new resolved data without refreshing the page.

  11. Mikastark commented on Jul 15, 2024

    @Mikastark

    I am using the same workaround as @Erbenos, employing a custom runGuardsAndResolvers. While it works, it feels quite hacky and incomplete.

    I am eagerly anticipating a more elegant solution—ideally, an option in router.navigate like onSameUrlNavigation: 'reloadGuardsAndResolvers'.

    In the meantime, I am considering avoiding the use of resolvers for data that requires reloading. Thoughts?

  12. Erbenos commented on Jul 15, 2024

    @Erbenos
    Contributor

    Having onSameUrlNavigation: 'reloadGuardsAndResolvers'. in router.navigate would not allow you to selectively re-resolve subset of resolvers as opposed to all of them. Current API already allows for this (in a way thats not polluting URL anyhow), as my example shows but its quite tedious. The issues I referenced, if addressed, would make it less so.

  13. Mikastark commented on Jul 15, 2024

    @Mikastark

    Perhaps a new option should be considered to explicitly specify which resolver(s) should be triggered again.

    router.navigate([], {
      runResolvers: [resolverFnA, resolverFnB] // 'all' value will run all guards and resolvers
    })
    
    // or
    
    router.navigate([], {
      runResolvers: ['resolvedEntryA', 'resolvedEntryB'] // 'all' value will run all guards and resolvers
    })
  14. atscott commented on Jan 21, 2025

    @atscott
    Contributor

    This is likely something we will be investigating with the integration of resource/signals in the router.

  15. regalialong commented on Aug 23, 2026

    @regalialong

    I'm usually allergic about bumping, but since signalizing / resourcing the router is in full swing, is this still considered?

    For my use case, I did a mutation on the fetched data, so I know the data on the page is invalid now, but I don't think I can communicate that to the resolver, which is a very annoying gap.

    I think #64938 makes Erbenos's solution a bit nicer since you can get the router from DI, but #53946 is still open, so it's still not really clean to reimplement from the user side without copy-paste.

  16. atscott commented on Aug 24, 2026

    @atscott
    Contributor

    This will be marked as resolved when the resource integration is made public. There should be various ways of making this happen, either through reactivity, or through traversing the activated tree and calling reload on each of the resources.

  17. atscott commented on Sep 4, 2026

    @atscott
    Contributor

    Closing as completed with resource integration that will be available in 22.2 as dev preview. There’s no direct api for this but it should be doable through various mechanisms that feel much better than the previous runGuardsAndResolvers+renavigate

  18. angular-automatic-lock-bot commented on Oct 24, 2026

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  19. locked and limited conversation to collaborators on Oct 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: routercross-cutting: signalsfeaturefeature: under considerationfreq1: low

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions