diff --git a/adev/src/content/guide/di/defining-dependency-providers.md b/adev/src/content/guide/di/defining-dependency-providers.md index 84d4684f469..87217b8f44f 100644 --- a/adev/src/content/guide/di/defining-dependency-providers.md +++ b/adev/src/content/guide/di/defining-dependency-providers.md @@ -731,6 +731,10 @@ export const routes: Routes = [ ]; ``` +Services provided at the route level are available to all components and directives within that route, as well as to its guards and resolvers. + +Since these services are instantiated independently of the route’s components, they do not have direct access to route-specific information. + ## Library author patterns When creating Angular libraries, you often need to provide flexible configuration options for consumers while maintaining clean APIs. Angular's own libraries demonstrate powerful patterns for achieving this. diff --git a/adev/src/content/guide/routing/data-resolvers.md b/adev/src/content/guide/routing/data-resolvers.md index 232d688f5d5..6e1064bc5f2 100644 --- a/adev/src/content/guide/routing/data-resolvers.md +++ b/adev/src/content/guide/routing/data-resolvers.md @@ -6,6 +6,8 @@ Data resolvers allow you to fetch data before navigating to a route, ensuring th A data resolver is a service that implements the `ResolveFn` function. It runs before a route activates and can fetch data from APIs, databases, or other sources. The resolved data becomes available to the component through the `ActivatedRoute`. +Data resolvers have access to [services provided at the route level](guide/di/defining-dependency-providers#route-providers) as well as route-specific information via the `route` argument. + ## Why use data resolvers? Data resolvers solve common routing challenges: diff --git a/adev/src/content/guide/routing/route-guards.md b/adev/src/content/guide/routing/route-guards.md index 43dc343c990..0801de4f727 100644 --- a/adev/src/content/guide/routing/route-guards.md +++ b/adev/src/content/guide/routing/route-guards.md @@ -39,14 +39,16 @@ Angular provides four types of route guards, each serving different purposes: +All the guards have access to [services provided at the route level](guide/di/defining-dependency-providers#route-providers) as well as route-specific information via the `route` argument. + ### CanActivate The `CanActivate` guard determines whether a user can access a route. It is most commonly used for authentication and authorization. It has access to the following default arguments: -- `route: ActivatedRouteSnapshot` - Contains information about the route being activated -- `state: RouterStateSnapshot` - Contains the router's current state +- `route`: `ActivatedRouteSnapshot` - Contains information about the route being activated +- `state`: `RouterStateSnapshot` - Contains the router's current state It can return the [standard return guard types](#route-guard-return-types). @@ -70,8 +72,8 @@ The `CanActivateChild` guard determines whether a user can access child routes o It has access to the following default arguments: -- `childRoute: ActivatedRouteSnapshot` - Contains information about the "future" snapshot (i.e., state the router is attempting to navigate to) of the child route being activated -- `state: RouterStateSnapshot` - Contains the router's current state +- `childRoute`: `ActivatedRouteSnapshot` - Contains information about the "future" snapshot (i.e., state the router is attempting to navigate to) of the child route being activated +- `state`: `RouterStateSnapshot` - Contains the router's current state It can return the [standard return guard types](#route-guard-return-types). @@ -93,10 +95,10 @@ The `CanDeactivate` guard determines whether a user can leave a route. A common It has access to the following default arguments: -- `component: T` - The component instance being deactivated -- `currentRoute: ActivatedRouteSnapshot` - Contains information about the current route -- `currentState: RouterStateSnapshot` - Contains the current router state -- `nextState: RouterStateSnapshot` - Contains the next router state being navigated to +- `component`: `T` - The component instance being deactivated +- `currentRoute`: `ActivatedRouteSnapshot` - Contains information about the current route +- `currentState`: `RouterStateSnapshot` - Contains the current router state +- `nextState`: `RouterStateSnapshot` - Contains the next router state being navigated to It can return the [standard return guard types](#route-guard-return-types). @@ -121,8 +123,8 @@ The `CanMatch` guard determines whether a route can be matched during path match It has access to the following default arguments: -- `route: Route` - The route configuration being evaluated -- `segments: UrlSegment[]` - The URL segments that have not been consumed by previous parent route evaluations +- `route`: `Route` - The route configuration being evaluated +- `segments`: `UrlSegment[]` - The URL segments that have not been consumed by previous parent route evaluations It can return the [standard return guard types](#route-guard-return-types), but when it returns `false`, Angular tries other matching routes instead of completely blocking navigation.