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

Function routerResource

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

Source from the content-addressed store, hash-verified

35 * during navigation transitions and handling rollback recovery.
36 */
37export function routerResource<T>(source: Resource<T>): Resource<T> & {reload(): boolean} {
38 ngDevMode && assertInInjectionContext(routerResource);
39 const injector = inject(Injector);
40 const router = injector.get(Router);
41
42 const {snapshot: snapshotSignal, frozenSnapshot} = createTransactionalSnapshot(
43 source,
44 router,
45 injector,
46 );
47
48 const res = resourceFromSnapshots(snapshotSignal) as Resource<T> & {reload(): boolean};
49
50 if (typeof (source as any).reload === 'function') {
51 res.reload = function (): boolean {
52 // If the resource is currently frozen (e.g., during an active navigation transition
53 // or while recovering from a cancelled navigation), we reject manual reload requests.
54 // Triggering a reload during an active navigation (where the resource may already be
55 // reactively loading new parameters behind the scenes) would disrupt the router's resource
56 // tracking for the transition. Similarly, during a rollback recovery, the router is
57 // already managing the resource reload to restore the previous state.
58 if (frozenSnapshot() !== null) {
59 return false;
60 }
61 return (source as any).reload();
62 };
63 } else {
64 res.reload = () => false;
65 }
66
67 return res;
68}
69
70/**
71 * Creates a signal that tracks the resource snapshot and handles transactional behavior

Callers 2

createWrappedResourceFunction · 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