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
Next Next commit
fixup! Create url tree without currentUrlTree
  • Loading branch information
atscott committed May 3, 2022
commit ce8f633d4b664e0154362ecacfe07f0b9857d79b
5 changes: 0 additions & 5 deletions packages/router/src/create_url_tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,6 @@ function findNewStartingPosition(
if (target.parent === null) {
return new Position(target, true, 0);
}
// if (indexOfLastConsumedSegmentInOutlet === -1) {
// // Pathless ActivatedRoute can be _lastPathIndex === -1 but should not process children
// // see issue #26224, #13011, #35687
// return new Position(segmentGroup, false, 0);
// }

const modifier = isMatrixParams(nav.commands[0]) ? 0 : 1;
const index = target.segments.length - 1 + modifier;
Expand Down
41 changes: 24 additions & 17 deletions packages/router/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {standardizeConfig, validateConfig} from './utils/config';
import {Checks, getAllRouteGuards} from './utils/preactivation';
import {isUrlTree} from './utils/type_guards';

const NG_DEV_MODE = (typeof ngDevMode === 'undefined' || !!ngDevMode);

const NG_DEV_MODE = typeof ngDevMode === 'undefined' || !!ngDevMode;

Expand Down Expand Up @@ -1220,12 +1221,16 @@ export class Router {
q = this.removeEmptyProps(q);
}

let targetGroup: UrlSegmentGroup|undefined;
let relativeToUrlSegmentGroup: UrlSegmentGroup|undefined;
try {
targetGroup = createSegmentGroupFromRoute(a.root.snapshot, a.snapshot).targetGroup;
relativeToUrlSegmentGroup = createSegmentGroupFromRoute(a.snapshot);
} catch (e: unknown) {
NG_DEV_MODE &&
console.warn(`${
a.snapshot} has an invalid structure. This is likely due to an incomplete mock in tests.`);
}
return createUrlTree(targetGroup ?? this.currentUrlTree.root, commands, q, f ?? null);
return createUrlTree(
relativeToUrlSegmentGroup ?? this.currentUrlTree.root, commands, q, f ?? null);
}

/**
Expand Down Expand Up @@ -1551,20 +1556,22 @@ function isBrowserTriggeredNavigation(source: 'imperative'|'popstate'|'hashchang
return source !== 'imperative';
}

function createSegmentGroupFromRoute(
route: ActivatedRouteSnapshot, targetRoute: ActivatedRouteSnapshot):
{targetGroup: UrlSegmentGroup|undefined, root: UrlSegmentGroup} {
const childOutlets: {[outlet: string]: UrlSegmentGroup} = {};
function createSegmentGroupFromRoute(route: ActivatedRouteSnapshot): UrlSegmentGroup {
let targetGroup: UrlSegmentGroup|undefined;
for (const childSnapshot of route.children) {
const {root, targetGroup: targetGroupInChild} =
createSegmentGroupFromRoute(childSnapshot, targetRoute);
targetGroup = targetGroup ?? targetGroupInChild;
childOutlets[childSnapshot.outlet] = root;
}
const root = new UrlSegmentGroup(route.url, childOutlets);
if (route === targetRoute) {
targetGroup = root;

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;
}
return {root, targetGroup};
const rootSegmentGroup = createSegmentGroupFromRouteRecursive(route.root);

return targetGroup ?? rootSegmentGroup;
}