Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix(router): handle parenthesized outlets without a name in DefaultUr…
…lSerializer

Previously, the `DefaultUrlSerializer` would incorrectly parse URLs with a parenthesized outlet that did not have a name, such as `/(left)`. This would result in an `undefined` outlet name in the serialized URL.

This commit fixes the issue by ensuring that parenthesized outlets without a name are treated as primary outlets.

fixes #58516. Based on the description, either the URL was constructed
manually or by custom serializer.
  • Loading branch information
atscott committed Oct 21, 2025
commit 8a9f23316b865c7a7201e182e31f9cff664c585c
4 changes: 2 additions & 2 deletions packages/router/src/url_tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ class UrlParser {
);
}

let outletName: string = undefined!;
let outletName: string | undefined;
if (path.indexOf(':') > -1) {
outletName = path.slice(0, path.indexOf(':'));
this.capture(outletName);
Expand All @@ -727,7 +727,7 @@ class UrlParser {
}

const children = this.parseChildren();
segments[outletName] =
segments[outletName ?? PRIMARY_OUTLET] =
Object.keys(children).length === 1 && children[PRIMARY_OUTLET]
? children[PRIMARY_OUTLET]
: new UrlSegmentGroup([], children);
Expand Down
17 changes: 17 additions & 0 deletions packages/router/test/url_tree.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,23 @@ describe('UrlTree', () => {
const p = router.parseUrl(serialized);
expect(router.serializeUrl(p)).toBe(serialized);
});

it('should work with named outlet with primary and immediate named siblings', () => {
const router = TestBed.inject(Router);
const tree = router.createUrlTree([
{
outlets: {
primary: ['Home'],
app: ['Welcome'],
dock: [{outlets: {primary: 'left', 1: ['One', {pinned: true}]}}],
},
},
]);
const url = tree.toString();
expect(url).toBe('/Home(app:Welcome//dock:/(left//1:One;pinned=true))');
const tree2 = serializer.parse(url);
expect(serializer.serialize(tree2)).toBe(url);
});
});

describe('containsTree', () => {
Expand Down