MOBILE-3320 course: Fix regex patch matcher

main
Noel De Martin 2021-06-17 17:23:36 +02:00
parent ae74cdb91f
commit 81876ca518
2 changed files with 11 additions and 6 deletions

View File

@ -17,7 +17,7 @@ import { UrlSegment, UrlSegmentGroup } from '@angular/router';
import { mock } from '@/testing/utils';
import { buildRegExpUrlMatcher } from '../app-routing.module';
import { buildRegExpUrlMatcher } from './app-routing.module';
describe('Routing utils', () => {
@ -35,6 +35,7 @@ describe('Routing utils', () => {
);
testMatcher('baz/foo/bar', null);
testMatcher('foobar', null);
testMatcher('foo', ['foo']);
testMatcher('foo/baz', ['foo']);
testMatcher('foo/bar/bar/baz', ['foo', 'bar', 'bar']);

View File

@ -113,14 +113,18 @@ export function buildRegExpUrlMatcher(regexp: RegExp): UrlMatcher {
}
// Consume segments that match.
const [consumed] = segments.slice(1).reduce(([consumed, path], segment) => path === match
? [consumed, path]
:[
consumed.concat(segment),
const [consumedSegments, consumedPath] = segments.slice(1).reduce(([segments, path], segment) => path === match
? [segments, path]
: [
segments.concat(segment),
`${path}/${segment.path}`,
], [[segments[0]] as UrlSegment[], segments[0].path]);
return { consumed };
if (consumedPath !== match) {
return null;
}
return { consumed: consumedSegments };
};
}