diff --git a/packages/router/src/recognize.ts b/packages/router/src/recognize.ts index e316fa1032..90200debf7 100644 --- a/packages/router/src/recognize.ts +++ b/packages/router/src/recognize.ts @@ -181,7 +181,9 @@ function match(segmentGroup: UrlSegmentGroup, route: Route, segments: UrlSegment const posParams: {[n: string]: string} = {}; forEach(res.posParams !, (v: UrlSegment, k: string) => { posParams[k] = v.path; }); - const parameters = {...posParams, ...res.consumed[res.consumed.length - 1].parameters}; + const parameters = res.consumed.length > 0 ? + {...posParams, ...res.consumed[res.consumed.length - 1].parameters} : + posParams; return {consumedSegments: res.consumed, lastChild: res.consumed.length, parameters}; } diff --git a/packages/router/test/recognize.spec.ts b/packages/router/test/recognize.spec.ts index a90f99ecca..8da65f3f3c 100644 --- a/packages/router/test/recognize.spec.ts +++ b/packages/router/test/recognize.spec.ts @@ -658,6 +658,26 @@ describe('recognize', () => { checkActivatedRoute(a.firstChild !, 'b', {}, ComponentB); }); }); + + it('should work with terminal route', () => { + const matcher = (s: any, g: any, r: any) => s.length === 0 ? ({consumed: s}) : null; + + checkRecognize([{matcher, component: ComponentA}] as any, '', (s: RouterStateSnapshot) => { + const a = s.root.firstChild !; + checkActivatedRoute(a, '', {}, ComponentA); + }); + }); + + it('should work with child terminal route', () => { + const matcher = (s: any, g: any, r: any) => s.length === 0 ? ({consumed: s}) : null; + + checkRecognize( + [{path: 'a', component: ComponentA, children: [{matcher, component: ComponentB}]}] as any, + 'a', (s: RouterStateSnapshot) => { + const a = s.root.firstChild !; + checkActivatedRoute(a, 'a', {}, ComponentA); + }); + }); }); describe('query parameters', () => {