Permalink
Browse files

fix(router): fix wildcard route with lazy loaded module (again) (#18139)

Closes #13848

Description:
We doesn't handle children of wildcard route properly link. It's always an empty array.

Created from #13851

PR Close #18139
  • Loading branch information...
jasonaden authored and IgorMinar committed Jul 14, 2017
1 parent fa0e8ef commit 8c991756fa87db471a57a6786781ed8cda363ec5
Showing with 26 additions and 15 deletions.
  1. +23 −13 packages/router/src/recognize.ts
  2. +3 −2 packages/router/test/integration.spec.ts
@@ -109,29 +109,33 @@ class Recognizer {
if ((route.outlet || PRIMARY_OUTLET) !== outlet) throw new NoMatch();
let snapshot: ActivatedRouteSnapshot;
let consumedSegments: UrlSegment[] = [];
let rawSlicedSegments: UrlSegment[] = [];
if (route.path === '**') {
const params = segments.length > 0 ? last(segments) !.parameters : {};
const snapshot = new ActivatedRouteSnapshot(
snapshot = new ActivatedRouteSnapshot(
segments, params, Object.freeze(this.urlTree.queryParams), this.urlTree.fragment !,
getData(route), outlet, route.component !, route, getSourceSegmentGroup(rawSegment),
getPathIndexShift(rawSegment) + segments.length, getResolve(route));
return [new TreeNode<ActivatedRouteSnapshot>(snapshot, [])];
} else {
const result: MatchResult = match(rawSegment, route, segments);
consumedSegments = result.consumedSegments;
rawSlicedSegments = segments.slice(result.lastChild);
snapshot = new ActivatedRouteSnapshot(
consumedSegments, result.parameters, Object.freeze(this.urlTree.queryParams),
this.urlTree.fragment !, getData(route), outlet, route.component !, route,
getSourceSegmentGroup(rawSegment),
getPathIndexShift(rawSegment) + consumedSegments.length, getResolve(route));
}
const {consumedSegments, parameters, lastChild} = match(rawSegment, route, segments);
const rawSlicedSegments = segments.slice(lastChild);
const childConfig = getChildConfig(route);
const childConfig: Route[] = getChildConfig(route);
const {segmentGroup, slicedSegments} =
split(rawSegment, consumedSegments, rawSlicedSegments, childConfig);
const snapshot = new ActivatedRouteSnapshot(
consumedSegments, parameters, Object.freeze(this.urlTree.queryParams),
this.urlTree.fragment !, getData(route), outlet, route.component !, route,
getSourceSegmentGroup(rawSegment), getPathIndexShift(rawSegment) + consumedSegments.length,
getResolve(route));
if (slicedSegments.length === 0 && segmentGroup.hasChildren()) {
const children = this.processChildren(childConfig, segmentGroup);
return [new TreeNode<ActivatedRouteSnapshot>(snapshot, children)];
@@ -166,7 +170,13 @@ function getChildConfig(route: Route): Route[] {
return [];
}
function match(segmentGroup: UrlSegmentGroup, route: Route, segments: UrlSegment[]) {
interface MatchResult {
consumedSegments: UrlSegment[];
lastChild: number;
parameters: any;
}
function match(segmentGroup: UrlSegmentGroup, route: Route, segments: UrlSegment[]): MatchResult {
if (route.path === '') {
if (route.pathMatch === 'full' && (segmentGroup.hasChildren() || segments.length > 0)) {
throw new NoMatch();
@@ -3470,10 +3470,10 @@ describe('Integration', () => {
declarations: [LazyLoadedComponent],
imports: [RouterModule.forChild([{path: '', component: LazyLoadedComponent}])],
})
class LoadedModule {
class LazyLoadedModule {
}
loader.stubbedModules = {lazy: LoadedModule};
loader.stubbedModules = {lazy: LazyLoadedModule};
const fixture = createRoot(router, RootCmp);
router.resetConfig([{path: '**', loadChildren: 'lazy'}]);
@@ -3482,6 +3482,7 @@ describe('Integration', () => {
advance(fixture);
expect(location.path()).toEqual('/lazy');
expect(fixture.nativeElement).toHaveText('lazy-loaded');
})));
describe('preloading', () => {

0 comments on commit 8c99175

Please sign in to comment.