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

Function routerResource

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

Source from the content-addressed store, hash-verified

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