Skip to content

Commit 0696ab6

Browse files
committed
fix(router): Should not freeze original object used for route data (#53635)
This was broken in 3278966 where the new code fails to copy the data object when not inheriting data. fixes #53632 PR Close #53635
1 parent b131c3b commit 0696ab6

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

packages/router/src/router_state.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,8 @@ export function getInherited(
265265
};
266266
} else {
267267
inherited = {
268-
params: route.params,
269-
data: route.data,
268+
params: {...route.params},
269+
data: {...route.data},
270270
resolve: {...route.data, ...(route._resolvedData ?? {})}
271271
};
272272
}

packages/router/test/recognize.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ describe('recognize', async () => {
3131
expect(Object.isFrozen(child.params)).toBeTruthy();
3232
});
3333

34+
it('should freeze data object (but not original route data)', async () => {
35+
const someData = {a: 1};
36+
const s: RouterStateSnapshot =
37+
await recognize([{path: '**', component: ComponentA, data: someData}], 'a');
38+
checkActivatedRoute(s.root, '', {}, RootComponent);
39+
const child = s.root.firstChild!;
40+
expect(Object.isFrozen(child.data)).toBeTruthy();
41+
expect(Object.isFrozen(someData)).toBeFalsy();
42+
});
43+
3444
it('should support secondary routes', async () => {
3545
const s: RouterStateSnapshot = await recognize(
3646
[

0 commit comments

Comments
 (0)