MCPcopy Create free account
hub / github.com/angular/angular / routerResource

Function routerResource

packages/router/src/router_resource.ts:74–109  ·  view source on GitHub ↗
(source: Resource<T>)

Source from the content-addressed store, hash-verified

72 * during navigation transitions and handling rollback recovery.
73 */
74export function routerResource<T>(source: Resource<T>): Resource<T> & {reload(): boolean} {
75 ngDevMode && assertInInjectionContext(routerResource);
76 const injector = inject(Injector);
77 const router = injector.get(Router);
78
79 const {snapshot: snapshotSignal, frozenSnapshot} = createTransactionalSnapshot(
80 source,
81 router,
82 injector,
83 );
84
85 const res = resourceFromSnapshots(snapshotSignal) as unknown as InternalRouterResource<T>;
86
87 res[SOURCE_RESOURCE_SYMBOL] = source;
88 res[BLOCKING_SYMBOL] =
89 (source as unknown as InternalRouterResource<T>)[BLOCKING_SYMBOL] !== false;
90
91 if (typeof (source as any).reload === 'function') {
92 res.reload = function (): boolean {
93 // If the resource is currently frozen (e.g., during an active navigation transition
94 // or while recovering from a cancelled navigation), we reject manual reload requests.
95 // Triggering a reload during an active navigation (where the resource may already be
96 // reactively loading new parameters behind the scenes) would disrupt the router's resource
97 // tracking for the transition. Similarly, during a rollback recovery, the router is
98 // already managing the resource reload to restore the previous state.
99 if (frozenSnapshot() !== null) {
100 return false;
101 }
102 return (source as any).reload();
103 };
104 } else {
105 res.reload = () => false;
106 }
107
108 return res;
109}
110
111/**
112 * Creates a signal that tracks the resource snapshot and handles transactional behavior

Callers 3

createWrappedResourceFunction · 0.90
setupNewRouterResourcesFunction · 0.90

Calls 6

assertInInjectionContextFunction · 0.90
injectFunction · 0.90
resourceFromSnapshotsFunction · 0.90
getMethod · 0.65
reloadMethod · 0.65

Tested by

no test coverage detected