Skip to content

Commit cfd8ed3

Browse files
atscottthePunderWoman
authored andcommitted
fix(router): Fix outlet serialization and parsing with no primary children (#64505)
this fixes tree creation, serialization, and parsing of trees created with children outlets and no primary path fixes #62384 PR Close #64505
1 parent de8af17 commit cfd8ed3

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

packages/router/src/url_tree.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ class UrlParser {
728728

729729
const children = this.parseChildren();
730730
segments[outletName] =
731-
Object.keys(children).length === 1
731+
Object.keys(children).length === 1 && children[PRIMARY_OUTLET]
732732
? children[PRIMARY_OUTLET]
733733
: new UrlSegmentGroup([], children);
734734
this.consumeOptional('//');

packages/router/test/url_tree.spec.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88

9-
import {exactMatchOptions, subsetMatchOptions} from '../src/router';
9+
import {TestBed} from '@angular/core/testing';
10+
import {exactMatchOptions, Router, subsetMatchOptions} from '../src/router';
1011
import {containsTree, DefaultUrlSerializer} from '../src/url_tree';
1112

1213
describe('UrlTree', () => {
@@ -31,6 +32,14 @@ describe('UrlTree', () => {
3132
const tree = serializer.parse('/path/to?first=http://foo/bar?baz=true&second=123');
3233
expect(tree.queryParams).toEqual({'first': 'http://foo/bar?baz=true', 'second': '123'});
3334
});
35+
36+
it('create, serialize, parse, serialize results in same serialized tree with outlet and no primary children', () => {
37+
const router = TestBed.inject(Router);
38+
const th = router.createUrlTree(['/', {outlets: {a: ['a'], b: [{outlets: {a: ['b1']}}]}}]);
39+
const serialized = router.serializeUrl(th);
40+
const p = router.parseUrl(serialized);
41+
expect(router.serializeUrl(p)).toBe(serialized);
42+
});
3443
});
3544

3645
describe('containsTree', () => {

0 commit comments

Comments
 (0)