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

Function routerResource

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

Source from the content-addressed store, hash-verified

56 * during navigation transitions and handling rollback recovery.
57 */
58export 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

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