Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fixup! Create url tree without currentUrlTree
  • Loading branch information
atscott committed May 3, 2022
commit 6fdb775e1ad994fc013188be5eda51d55fc73c32
38 changes: 38 additions & 0 deletions packages/router/src/create_url_tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,48 @@
*/

import {squashSegmentGroup} from './apply_redirects';
import {ActivatedRouteSnapshot} from './router_state';
import {Params, PRIMARY_OUTLET} from './shared';
import {createRoot, UrlSegment, UrlSegmentGroup, UrlTree} from './url_tree';
import {forEach, last, shallowEqual} from './utils/collection';

/**
*
* @publicApi
* @param relativeTo
* @param commands
* @param queryParams
* @param fragment
* @returns
*/
export function createUrlTreeFromSnapshot(
relativeTo: ActivatedRouteSnapshot, commands: any[], queryParams: Params|null,
fragment: string|null): UrlTree {
const relativeToUrlSegmentGroup = createSegmentGroupFromRoute(relativeTo);
return createUrlTree(relativeToUrlSegmentGroup, commands, queryParams, fragment);
}

export function createSegmentGroupFromRoute(route: ActivatedRouteSnapshot): UrlSegmentGroup {
let targetGroup: UrlSegmentGroup|undefined;

function createSegmentGroupFromRouteRecursive(currentRoute: ActivatedRouteSnapshot) {
const childOutlets: {[outlet: string]: UrlSegmentGroup} = {};
for (const childSnapshot of currentRoute.children) {
const root = createSegmentGroupFromRouteRecursive(childSnapshot);
childOutlets[childSnapshot.outlet] = root;
}
const segmentGroup = new UrlSegmentGroup(currentRoute.url, childOutlets);
if (currentRoute === route) {
targetGroup = segmentGroup;
}
return segmentGroup;
}
const rootCandidate = createSegmentGroupFromRouteRecursive(route.root);
const rootSegmentGroup = createRoot(rootCandidate);

return targetGroup ?? rootSegmentGroup;
}

export function createUrlTree(
relativeTo: UrlSegmentGroup, commands: any[], queryParams: Params|null,
fragment: string|null): UrlTree {
Expand Down
23 changes: 1 addition & 22 deletions packages/router/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {BehaviorSubject, combineLatest, EMPTY, Observable, of, Subject, Subscrip
import {catchError, defaultIfEmpty, filter, finalize, map, switchMap, take, tap} from 'rxjs/operators';

import {createRouterState} from './create_router_state';
import {createUrlTree} from './create_url_tree';
import {createSegmentGroupFromRoute, createUrlTree} from './create_url_tree';
import {Event, GuardsCheckEnd, GuardsCheckStart, NavigationCancel, NavigationEnd, NavigationError, NavigationStart, NavigationTrigger, ResolveEnd, ResolveStart, RouteConfigLoadEnd, RouteConfigLoadStart, RoutesRecognized} from './events';
import {QueryParamsHandling, Route, Routes} from './models';
import {activateRoutes} from './operators/activate_routes';
Expand Down Expand Up @@ -1574,24 +1574,3 @@ function validateCommands(commands: string[]): void {
function isBrowserTriggeredNavigation(source: 'imperative'|'popstate'|'hashchange') {
return source !== 'imperative';
}

function createSegmentGroupFromRoute(route: ActivatedRouteSnapshot): UrlSegmentGroup {
let targetGroup: UrlSegmentGroup|undefined;

function createSegmentGroupFromRouteRecursive(currentRoute: ActivatedRouteSnapshot) {
const childOutlets: {[outlet: string]: UrlSegmentGroup} = {};
for (const childSnapshot of currentRoute.children) {
const root = createSegmentGroupFromRouteRecursive(childSnapshot);
childOutlets[childSnapshot.outlet] = root;
}
const segmentGroup = new UrlSegmentGroup(currentRoute.url, childOutlets);
if (currentRoute === route) {
targetGroup = segmentGroup;
}
return segmentGroup;
}
const rootCandidate = createSegmentGroupFromRouteRecursive(route.root);
const rootSegmentGroup = createRoot(rootCandidate);

return targetGroup ?? rootSegmentGroup;
}