Back to results for “Templates”
Angular › Router Guards & Resolvers

What is a resolver in Angular routing, and what problem does it solve?

Intermediate

Answer

A resolver fetches data before a route actually activates, ensuring the component already has the data it needs the moment it appears on screen, rather than showing an empty or loading state and then fetching the data afterward inside the component itself.
export const userResolver: ResolveFn<User> = (route) => {
  const userService = inject(UserService);
  return userService.getUser(route.params['id']);
};

{ path: 'users/:id', component: UserDetailComponent, resolve: { user: userResolver } }
Real-world example A user profile page shows the user's details immediately upon arriving on the page, with no visible loading flicker at all, because a resolver already fetched that data before the route finished navigating.

Common follow-ups: How does a component actually access the data provided by a resolver?;What happens to navigation if the resolver's data fetch fails?