Skip to content

Commit 85d5242

Browse files
atscottjosephperrott
authored andcommitted
fix(router): Ensure all outlets are used when commands have a prefix (#39456)
When there is a primary outlet present in the outlets map and the object is also prefixed with some other commands, the current logic only uses the primary outlet and ignores the others. This change ensures that all outlets are respected at the segment level when prefixed with other commands. PR Close #39456
1 parent 8f36c21 commit 85d5242

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

packages/router/src/create_url_tree.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,6 @@ function createPositionApplyingDoubleDots(
186186
return new Position(g, false, ci - dd);
187187
}
188188

189-
function getPath(command: any): any {
190-
if (isCommandWithOutlets(command)) {
191-
return command.outlets[PRIMARY_OUTLET];
192-
}
193-
return `${command}`;
194-
}
195-
196189
function getOutlets(commands: any[]): {[k: string]: any[]} {
197190
if (isCommandWithOutlets(commands[0])) {
198191
return commands[0].outlets;
@@ -259,7 +252,14 @@ function prefixedWith(segmentGroup: UrlSegmentGroup, startIndex: number, command
259252
while (currentPathIndex < segmentGroup.segments.length) {
260253
if (currentCommandIndex >= commands.length) return noMatch;
261254
const path = segmentGroup.segments[currentPathIndex];
262-
const curr = getPath(commands[currentCommandIndex]);
255+
const command = commands[currentCommandIndex];
256+
// Do not try to consume command as part of the prefixing if it has outlets because it can
257+
// contain outlets other than the one being processed. Consuming the outlets command would
258+
// result in other outlets being ignored.
259+
if (isCommandWithOutlets(command)) {
260+
break;
261+
}
262+
const curr = `${command}`;
263263
const next =
264264
currentCommandIndex < commands.length - 1 ? commands[currentCommandIndex + 1] : null;
265265

@@ -298,7 +298,7 @@ function createNewSegmentGroup(
298298
continue;
299299
}
300300

301-
const curr = getPath(command);
301+
const curr = isCommandWithOutlets(command) ? command.outlets[PRIMARY_OUTLET] : `${command}`;
302302
const next = (i < commands.length - 1) ? commands[i + 1] : null;
303303
if (curr && next && isMatrixParams(next)) {
304304
paths.push(new UrlSegment(curr, stringify(next)));

packages/router/test/create_url_tree.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,13 @@ describe('createUrlTree', () => {
150150
expect(serializer.serialize(t)).toEqual('/parent/child');
151151
});
152152

153-
xit('should support updating secondary and primary outlets with prefix', () => {
153+
it('should support updating secondary and primary outlets with prefix', () => {
154154
const p = serializer.parse('/parent/child');
155155
const t = createRoot(p, ['parent', {outlets: {primary: 'child', secondary: 'popup'}}]);
156156
expect(serializer.serialize(t)).toEqual('/parent/(child//secondary:popup)');
157157
});
158158

159-
xit('should support updating two outlets at the same time relative to non-root segment', () => {
159+
it('should support updating two outlets at the same time relative to non-root segment', () => {
160160
const p = serializer.parse('/parent/child');
161161
const t = create(
162162
p.root.children[PRIMARY_OUTLET], 0 /* relativeTo: 'parent' */, p,

0 commit comments

Comments
 (0)