File tree 3 files changed +28
-0
lines changed
libs/router/src/activated-route
3 files changed +28
-0
lines changed Original file line number Diff line number Diff line change
1
+ import {
2
+ APP_INITIALIZER ,
3
+ DestroyRef ,
4
+ inject ,
5
+ Provider ,
6
+ } from '@angular/core' ;
7
+ import { takeUntilDestroyed } from '@angular/core/rxjs-interop' ;
8
+
9
+ import { DaffRouterActivatedRoute } from './service' ;
10
+
11
+ /**
12
+ * Provides the initializer for {@link DaffRouterActivatedRoute}.
13
+ */
14
+ export const provideDaffRouterActivatedRoute = ( ) : Provider => ( {
15
+ provide : APP_INITIALIZER ,
16
+ multi : true ,
17
+ useFactory : ( ) => {
18
+ const service = inject ( DaffRouterActivatedRoute ) ;
19
+ const destroyRef = inject ( DestroyRef ) ;
20
+ return ( ) => {
21
+ service . route$ . pipe (
22
+ takeUntilDestroyed ( destroyRef ) ,
23
+ ) . subscribe ( ) ;
24
+ } ;
25
+ } ,
26
+ } ) ;
Original file line number Diff line number Diff line change 1
1
export * from './service' ;
2
+ export * from './provider' ;
Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ const getActivatedRoute = (routerState: RouterState): ActivatedRoute => {
27
27
* Note that this service operates by listening to router events. It is therefore recommended to
28
28
* inject this service in the root and subscribe to `route$` on app init so that all routing events are captured.
29
29
* The consumer can then subscribe at any later time (after all navigations) and the emission stream will be replayed.
30
+ * {@link provideDaffRouterActivatedRoute} is the recommended way to do this.
30
31
*/
31
32
@Injectable ( {
32
33
providedIn : 'root' ,
You can’t perform that action at this time.
0 commit comments