Skip to content

Commit

Permalink
fix(router): terminal route in custom matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
SamVerschueren authored and alxhub committed Jul 18, 2017
1 parent 3b588fe commit b399cb2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/router/src/recognize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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};
}
Expand Down
20 changes: 20 additions & 0 deletions packages/router/test/recognize.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit b399cb2

Please sign in to comment.