(source: Resource<T>)
| 56 | * during navigation transitions and handling rollback recovery. |
| 57 | */ |
| 58 | export function routerResource<T>(source: Resource<T>): Resource<T> & {reload(): boolean} { |
| 59 | ngDevMode && assertInInjectionContext(routerResource); |
| 60 | const injector = inject(Injector); |
| 61 | const router = injector.get(Router); |
| 62 | |
| 63 | const {snapshot: snapshotSignal, frozenSnapshot} = createTransactionalSnapshot( |
| 64 | source, |
| 65 | router, |
| 66 | injector, |
| 67 | ); |
| 68 | |
| 69 | const res = resourceFromSnapshots(snapshotSignal) as unknown as InternalRouterResource<T>; |
| 70 | |
| 71 | if ((source as unknown as InternalRouterResource<T>)[BLOCKING_SYMBOL] === false) { |
| 72 | res[BLOCKING_SYMBOL] = false; |
| 73 | } else { |
| 74 | res[BLOCKING_SYMBOL] = true; |
| 75 | } |
| 76 | |
| 77 | if (typeof (source as any).reload === 'function') { |
| 78 | res.reload = function (): boolean { |
| 79 | // If the resource is currently frozen (e.g., during an active navigation transition |
| 80 | // or while recovering from a cancelled navigation), we reject manual reload requests. |
| 81 | // Triggering a reload during an active navigation (where the resource may already be |
| 82 | // reactively loading new parameters behind the scenes) would disrupt the router's resource |
| 83 | // tracking for the transition. Similarly, during a rollback recovery, the router is |
| 84 | // already managing the resource reload to restore the previous state. |
| 85 | if (frozenSnapshot() !== null) { |
| 86 | return false; |
| 87 | } |
| 88 | return (source as any).reload(); |
| 89 | }; |
| 90 | } else { |
| 91 | res.reload = () => false; |
| 92 | } |
| 93 | |
| 94 | return res; |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * Creates a signal that tracks the resource snapshot and handles transactional behavior |
no test coverage detected