From 20cef5078dc86bc5d9831fafec076d912ad3521f Mon Sep 17 00:00:00 2001 From: miginmrs Date: Fri, 5 Oct 2018 19:22:06 +0100 Subject: [PATCH] fix(router): process empty path segment when preceding a named outlet (#26243) PR Close #10726 PR Close #26243 --- packages/router/src/recognize.ts | 8 ++++++++ packages/router/test/recognize.spec.ts | 14 ++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/packages/router/src/recognize.ts b/packages/router/src/recognize.ts index 6c3f8b327f..58cc5a7e27 100644 --- a/packages/router/src/recognize.ts +++ b/packages/router/src/recognize.ts @@ -70,6 +70,14 @@ class Recognizer { processSegmentGroup(config: Route[], segmentGroup: UrlSegmentGroup, outlet: string): TreeNode[] { if (segmentGroup.segments.length === 0 && segmentGroup.hasChildren()) { + const empties = config.filter(r => emptyPathMatch(segmentGroup, segmentGroup.segments, r)); + if (empties.length !== 0) { + try { + return this.processSegment(empties, segmentGroup, segmentGroup.segments, outlet); + } catch (e) { + if (!(e instanceof NoMatch)) throw e; + } + } return this.processChildren(config, segmentGroup); } diff --git a/packages/router/test/recognize.spec.ts b/packages/router/test/recognize.spec.ts index 0494f2fe66..827a8e5030 100644 --- a/packages/router/test/recognize.spec.ts +++ b/packages/router/test/recognize.spec.ts @@ -263,6 +263,20 @@ describe('recognize', () => { }); }); + it('should work with children outlets', () => { + checkRecognize( + [{ + path: '', + component: ComponentA, + children: [{path: 'b', outlet: 'b', component: ComponentB}] + }], + '(b:b)', (s: RouterStateSnapshot) => { + checkActivatedRoute((s as any).firstChild(s.root) !, '', {}, ComponentA); + checkActivatedRoute( + (s as any).firstChild((s as any).firstChild(s.root)) !, 'b', {}, ComponentB, 'b'); + }); + }); + it('should match when terminal', () => { checkRecognize( [{path: '', pathMatch: 'full', component: ComponentA}], '',