Resolve was deprecated in v15.2
And will be removed in v17
As mentioned in the deprecation note of Resolve
in @angular/router
it was deprecated in favor of ResolveFn
.
Deprecated: Class-based Route resolvers are deprecated in favor of functional resolvers.
An injectable class can be used as a functional guard using the
`inject` function: `resolve: {'user': () => inject(UserResolver).resolve()}`.
Steps to use the functional resolvers
Remove the deprecated Resolve
implementation from the addEditClient.ts
Add this function to your router or the service file or any other file with export
.
This will inject the AddEditClientService
and resolve the function you need. As you can see you can also use the route
and state
params and pass them to your function.
const addEditClietResolver: ResolveFn<any> =
(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) => {
return inject(AddEditClientService).getClientById();
};
And use it in the router path
{
path: 'clients/add-edit',
component: AddEditClientComponent,
resolve: {data: addEditClientResolver},
}
Or with a shorter approach by using the function directly in Route object
{
path: 'clients/add-edit',
component: AddEditClientComponent,
resolve: {data: () => inject(AddEditClientService).getClientById()},
}
You can checkout more about this in the Angular documentation