diff --git a/packages/router/src/apply_redirects.ts b/packages/router/src/apply_redirects.ts index 2cc993e10d2..52e8a1d226f 100644 --- a/packages/router/src/apply_redirects.ts +++ b/packages/router/src/apply_redirects.ts @@ -259,7 +259,7 @@ class ApplyRedirects { private expandRegularSegmentAgainstRouteUsingRedirect( ngModule: NgModuleRef, segmentGroup: UrlSegmentGroup, routes: Route[], route: Route, segments: UrlSegment[], outlet: string): Observable { - const {matched, consumedSegments, lastChild, positionalParamSegments} = + const {matched, consumedSegments, remainingSegments, positionalParamSegments} = match(segmentGroup, route, segments); if (!matched) return noMatch(segmentGroup); @@ -271,8 +271,7 @@ class ApplyRedirects { return this.lineralizeSegments(route, newTree).pipe(mergeMap((newSegments: UrlSegment[]) => { return this.expandSegment( - ngModule, segmentGroup, routes, newSegments.concat(segments.slice(lastChild)), outlet, - false); + ngModule, segmentGroup, routes, newSegments.concat(remainingSegments), outlet, false); })); } @@ -292,10 +291,9 @@ class ApplyRedirects { return of(new UrlSegmentGroup(segments, {})); } - const {matched, consumedSegments, lastChild} = match(rawSegmentGroup, route, segments); + const {matched, consumedSegments, remainingSegments} = match(rawSegmentGroup, route, segments); if (!matched) return noMatch(rawSegmentGroup); - const rawSlicedSegments = segments.slice(lastChild); const childConfig$ = this.getChildConfig(ngModule, route, segments); return childConfig$.pipe(mergeMap((routerConfig: LoadedRouterConfig) => { @@ -303,7 +301,7 @@ class ApplyRedirects { const childConfig = routerConfig.routes; const {segmentGroup: splitSegmentGroup, slicedSegments} = - split(rawSegmentGroup, consumedSegments, rawSlicedSegments, childConfig); + split(rawSegmentGroup, consumedSegments, remainingSegments, childConfig); // See comment on the other call to `split` about why this is necessary. const segmentGroup = new UrlSegmentGroup(splitSegmentGroup.segments, splitSegmentGroup.children); diff --git a/packages/router/src/recognize.ts b/packages/router/src/recognize.ts index cb12aa8172f..9df0c138694 100644 --- a/packages/router/src/recognize.ts +++ b/packages/router/src/recognize.ts @@ -155,7 +155,7 @@ export class Recognizer { let snapshot: ActivatedRouteSnapshot; let consumedSegments: UrlSegment[] = []; - let rawSlicedSegments: UrlSegment[] = []; + let remainingSegments: UrlSegment[] = []; if (route.path === '**') { const params = segments.length > 0 ? last(segments)!.parameters : {}; @@ -170,7 +170,7 @@ export class Recognizer { return null; } consumedSegments = result.consumedSegments; - rawSlicedSegments = segments.slice(result.lastChild); + remainingSegments = result.remainingSegments; snapshot = new ActivatedRouteSnapshot( consumedSegments, result.parameters, Object.freeze({...this.urlTree.queryParams}), @@ -182,7 +182,7 @@ export class Recognizer { const childConfig: Route[] = getChildConfig(route); const {segmentGroup, slicedSegments} = split( - rawSegment, consumedSegments, rawSlicedSegments, + rawSegment, consumedSegments, remainingSegments, // Filter out routes with redirectTo because we are trying to create activated route // snapshots and don't handle redirects here. That should have been done in // `applyRedirects`. diff --git a/packages/router/src/utils/config_matching.ts b/packages/router/src/utils/config_matching.ts index 52e625e8a3c..40ace3f9abf 100644 --- a/packages/router/src/utils/config_matching.ts +++ b/packages/router/src/utils/config_matching.ts @@ -16,7 +16,7 @@ import {getOutlet} from './config'; export interface MatchResult { matched: boolean; consumedSegments: UrlSegment[]; - lastChild: number; + remainingSegments: UrlSegment[]; parameters: {[k: string]: string}; positionalParamSegments: {[k: string]: UrlSegment}; } @@ -24,7 +24,7 @@ export interface MatchResult { const noMatch: MatchResult = { matched: false, consumedSegments: [], - lastChild: 0, + remainingSegments: [], parameters: {}, positionalParamSegments: {} }; @@ -39,7 +39,7 @@ export function match( return { matched: true, consumedSegments: [], - lastChild: 0, + remainingSegments: segments, parameters: {}, positionalParamSegments: {} }; @@ -60,7 +60,7 @@ export function match( return { matched: true, consumedSegments: res.consumed, - lastChild: res.consumed.length, + remainingSegments: segments.slice(res.consumed.length), // TODO(atscott): investigate combining parameters and positionalParamSegments parameters, positionalParamSegments: res.posParams ?? {}