2016-06-23 12:47:54 -04:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
|
2016-06-08 14:13:41 -04:00
|
|
|
import {Type} from '@angular/core';
|
|
|
|
import {Observable} from 'rxjs/Observable';
|
2016-06-15 19:45:19 -04:00
|
|
|
import {Observer} from 'rxjs/Observer';
|
2016-06-08 19:14:26 -04:00
|
|
|
import {of } from 'rxjs/observable/of';
|
2016-06-08 14:13:41 -04:00
|
|
|
|
2016-07-06 19:19:52 -04:00
|
|
|
import {Data, ResolveData, Route, Routes} from './config';
|
2016-06-27 17:00:07 -04:00
|
|
|
import {ActivatedRouteSnapshot, InheritedResolve, RouterStateSnapshot} from './router_state';
|
2016-06-19 17:44:20 -04:00
|
|
|
import {PRIMARY_OUTLET, Params} from './shared';
|
2016-07-25 15:15:07 -04:00
|
|
|
import {UrlSegment, UrlSegmentGroup, UrlTree, mapChildrenIntoArray} from './url_tree';
|
2016-06-14 17:55:59 -04:00
|
|
|
import {last, merge} from './utils/collection';
|
2016-06-08 14:13:41 -04:00
|
|
|
import {TreeNode} from './utils/tree';
|
2016-05-23 19:14:23 -04:00
|
|
|
|
2016-06-14 17:55:59 -04:00
|
|
|
class NoMatch {
|
2016-07-25 15:15:07 -04:00
|
|
|
constructor(public segmentGroup: UrlSegmentGroup = null) {}
|
2016-06-14 17:55:59 -04:00
|
|
|
}
|
2016-06-06 13:15:23 -04:00
|
|
|
|
2016-06-27 17:00:07 -04:00
|
|
|
class InheritedFromParent {
|
|
|
|
constructor(
|
2016-07-08 17:23:23 -04:00
|
|
|
public parent: InheritedFromParent, public snapshot: ActivatedRouteSnapshot,
|
|
|
|
public params: Params, public data: Data, public resolve: InheritedResolve) {}
|
2016-06-27 17:00:07 -04:00
|
|
|
|
|
|
|
get allParams(): Params {
|
|
|
|
return this.parent ? merge(this.parent.allParams, this.params) : this.params;
|
|
|
|
}
|
|
|
|
|
|
|
|
get allData(): Data { return this.parent ? merge(this.parent.allData, this.data) : this.data; }
|
|
|
|
|
2016-07-08 17:23:23 -04:00
|
|
|
static empty(snapshot: ActivatedRouteSnapshot): InheritedFromParent {
|
|
|
|
return new InheritedFromParent(null, snapshot, {}, {}, new InheritedResolve(null, {}));
|
2016-06-27 17:00:07 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-06 19:19:52 -04:00
|
|
|
export function recognize(rootComponentType: Type, config: Routes, urlTree: UrlTree, url: string):
|
|
|
|
Observable<RouterStateSnapshot> {
|
2016-08-02 18:31:56 -04:00
|
|
|
return new Recognizer(rootComponentType, config, urlTree, url).recognize();
|
2016-05-23 19:14:23 -04:00
|
|
|
}
|
|
|
|
|
2016-08-02 18:31:56 -04:00
|
|
|
class Recognizer {
|
|
|
|
constructor(
|
|
|
|
private rootComponentType: Type, private config: Routes, private urlTree: UrlTree,
|
|
|
|
private url: string) {}
|
2016-06-14 17:55:59 -04:00
|
|
|
|
2016-08-02 18:31:56 -04:00
|
|
|
recognize(): Observable<RouterStateSnapshot> {
|
|
|
|
try {
|
|
|
|
const rootSegmentGroup = split(this.urlTree.root, [], [], this.config).segmentGroup;
|
2016-06-14 17:55:59 -04:00
|
|
|
|
2016-08-02 18:31:56 -04:00
|
|
|
const children = this.processSegmentGroup(
|
|
|
|
this.config, rootSegmentGroup, InheritedFromParent.empty(null), PRIMARY_OUTLET);
|
|
|
|
|
|
|
|
const root = new ActivatedRouteSnapshot(
|
|
|
|
[], Object.freeze({}), Object.freeze(this.urlTree.queryParams), this.urlTree.fragment, {},
|
|
|
|
PRIMARY_OUTLET, this.rootComponentType, null, this.urlTree.root, -1,
|
|
|
|
InheritedResolve.empty);
|
|
|
|
|
|
|
|
const rootNode = new TreeNode<ActivatedRouteSnapshot>(root, children);
|
|
|
|
|
|
|
|
return of (new RouterStateSnapshot(this.url, rootNode));
|
2016-06-02 14:30:38 -04:00
|
|
|
|
2016-06-06 13:15:23 -04:00
|
|
|
} catch (e) {
|
2016-08-02 18:31:56 -04:00
|
|
|
if (e instanceof NoMatch) {
|
|
|
|
return new Observable<RouterStateSnapshot>(
|
|
|
|
(obs: Observer<RouterStateSnapshot>) =>
|
|
|
|
obs.error(new Error(`Cannot match any routes: '${e.segmentGroup}'`)));
|
|
|
|
} else {
|
|
|
|
return new Observable<RouterStateSnapshot>(
|
|
|
|
(obs: Observer<RouterStateSnapshot>) => obs.error(e));
|
|
|
|
}
|
2016-06-06 13:15:23 -04:00
|
|
|
}
|
|
|
|
}
|
2016-05-23 19:14:23 -04:00
|
|
|
|
2016-06-19 17:44:20 -04:00
|
|
|
|
2016-08-02 18:31:56 -04:00
|
|
|
processSegmentGroup(
|
|
|
|
config: Route[], segmentGroup: UrlSegmentGroup, inherited: InheritedFromParent,
|
|
|
|
outlet: string): TreeNode<ActivatedRouteSnapshot>[] {
|
|
|
|
if (segmentGroup.segments.length === 0 && segmentGroup.hasChildren()) {
|
|
|
|
return this.processChildren(config, segmentGroup, inherited);
|
|
|
|
} else {
|
|
|
|
return this.processSegment(config, segmentGroup, 0, segmentGroup.segments, inherited, outlet);
|
|
|
|
}
|
|
|
|
}
|
2016-06-14 17:55:59 -04:00
|
|
|
|
2016-08-02 18:31:56 -04:00
|
|
|
processChildren(config: Route[], segmentGroup: UrlSegmentGroup, inherited: InheritedFromParent):
|
|
|
|
TreeNode<ActivatedRouteSnapshot>[] {
|
|
|
|
const children = mapChildrenIntoArray(
|
|
|
|
segmentGroup,
|
|
|
|
(child, childOutlet) => this.processSegmentGroup(config, child, inherited, childOutlet));
|
|
|
|
checkOutletNameUniqueness(children);
|
|
|
|
sortActivatedRouteSnapshots(children);
|
|
|
|
return children;
|
|
|
|
}
|
2016-06-27 17:00:07 -04:00
|
|
|
|
2016-08-02 18:31:56 -04:00
|
|
|
processSegment(
|
|
|
|
config: Route[], segmentGroup: UrlSegmentGroup, pathIndex: number, segments: UrlSegment[],
|
|
|
|
inherited: InheritedFromParent, outlet: string): TreeNode<ActivatedRouteSnapshot>[] {
|
|
|
|
for (let r of config) {
|
|
|
|
try {
|
|
|
|
return this.processSegmentAgainstRoute(
|
|
|
|
r, segmentGroup, pathIndex, segments, inherited, outlet);
|
|
|
|
} catch (e) {
|
|
|
|
if (!(e instanceof NoMatch)) throw e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
throw new NoMatch(segmentGroup);
|
2016-05-23 19:14:23 -04:00
|
|
|
}
|
2016-06-06 13:15:23 -04:00
|
|
|
|
2016-08-02 18:31:56 -04:00
|
|
|
processSegmentAgainstRoute(
|
|
|
|
route: Route, rawSegment: UrlSegmentGroup, pathIndex: number, segments: UrlSegment[],
|
|
|
|
inherited: InheritedFromParent, outlet: string): TreeNode<ActivatedRouteSnapshot>[] {
|
|
|
|
if (route.redirectTo) throw new NoMatch();
|
|
|
|
|
|
|
|
if ((route.outlet ? route.outlet : PRIMARY_OUTLET) !== outlet) throw new NoMatch();
|
2016-06-14 17:55:59 -04:00
|
|
|
|
2016-08-02 18:31:56 -04:00
|
|
|
const newInheritedResolve = new InheritedResolve(inherited.resolve, getResolve(route));
|
2016-06-24 14:17:17 -04:00
|
|
|
|
2016-08-02 18:31:56 -04:00
|
|
|
if (route.path === '**') {
|
|
|
|
const params = segments.length > 0 ? last(segments).parameters : {};
|
|
|
|
const snapshot = new ActivatedRouteSnapshot(
|
|
|
|
segments, Object.freeze(merge(inherited.allParams, params)),
|
|
|
|
Object.freeze(this.urlTree.queryParams), this.urlTree.fragment,
|
|
|
|
merge(inherited.allData, getData(route)), outlet, route.component, route,
|
|
|
|
getSourceSegmentGroup(rawSegment), getPathIndexShift(rawSegment) + segments.length,
|
|
|
|
newInheritedResolve);
|
|
|
|
return [new TreeNode<ActivatedRouteSnapshot>(snapshot, [])];
|
|
|
|
}
|
|
|
|
|
|
|
|
const {consumedSegments, parameters, lastChild} =
|
|
|
|
match(rawSegment, route, segments, inherited.snapshot);
|
|
|
|
const rawSlicedSegments = segments.slice(lastChild);
|
|
|
|
const childConfig = getChildConfig(route);
|
2016-06-14 17:55:59 -04:00
|
|
|
|
2016-08-02 18:31:56 -04:00
|
|
|
const {segmentGroup, slicedSegments} =
|
|
|
|
split(rawSegment, consumedSegments, rawSlicedSegments, childConfig);
|
2016-07-08 17:23:23 -04:00
|
|
|
|
2016-08-02 18:31:56 -04:00
|
|
|
const snapshot = new ActivatedRouteSnapshot(
|
|
|
|
consumedSegments, Object.freeze(merge(inherited.allParams, parameters)),
|
|
|
|
Object.freeze(this.urlTree.queryParams), this.urlTree.fragment,
|
|
|
|
merge(inherited.allData, getData(route)), outlet, route.component, route,
|
|
|
|
getSourceSegmentGroup(rawSegment), getPathIndexShift(rawSegment) + consumedSegments.length,
|
|
|
|
newInheritedResolve);
|
2016-06-24 14:17:17 -04:00
|
|
|
|
2016-08-02 18:31:56 -04:00
|
|
|
const newInherited = route.component ?
|
|
|
|
InheritedFromParent.empty(snapshot) :
|
|
|
|
new InheritedFromParent(
|
|
|
|
inherited, snapshot, parameters, getData(route), newInheritedResolve);
|
2016-06-14 17:55:59 -04:00
|
|
|
|
2016-08-02 18:31:56 -04:00
|
|
|
if (slicedSegments.length === 0 && segmentGroup.hasChildren()) {
|
|
|
|
const children = this.processChildren(childConfig, segmentGroup, newInherited);
|
|
|
|
return [new TreeNode<ActivatedRouteSnapshot>(snapshot, children)];
|
|
|
|
|
|
|
|
} else if (childConfig.length === 0 && slicedSegments.length === 0) {
|
|
|
|
return [new TreeNode<ActivatedRouteSnapshot>(snapshot, [])];
|
|
|
|
|
|
|
|
} else {
|
|
|
|
const children = this.processSegment(
|
|
|
|
childConfig, segmentGroup, pathIndex + lastChild, slicedSegments, newInherited,
|
|
|
|
PRIMARY_OUTLET);
|
|
|
|
return [new TreeNode<ActivatedRouteSnapshot>(snapshot, children)];
|
|
|
|
}
|
2016-05-23 19:14:23 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-02 18:31:56 -04:00
|
|
|
function sortActivatedRouteSnapshots(nodes: TreeNode<ActivatedRouteSnapshot>[]): void {
|
|
|
|
nodes.sort((a, b) => {
|
|
|
|
if (a.value.outlet === PRIMARY_OUTLET) return -1;
|
|
|
|
if (b.value.outlet === PRIMARY_OUTLET) return 1;
|
|
|
|
return a.value.outlet.localeCompare(b.value.outlet);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-07-06 14:02:16 -04:00
|
|
|
function getChildConfig(route: Route): Route[] {
|
|
|
|
if (route.children) {
|
|
|
|
return route.children;
|
2016-07-06 19:19:52 -04:00
|
|
|
} else if (route.loadChildren) {
|
2016-07-06 14:02:16 -04:00
|
|
|
return (<any>route)._loadedConfig.routes;
|
|
|
|
} else {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-08 17:23:23 -04:00
|
|
|
function match(
|
2016-07-25 15:15:07 -04:00
|
|
|
segmentGroup: UrlSegmentGroup, route: Route, segments: UrlSegment[],
|
|
|
|
parent: ActivatedRouteSnapshot) {
|
2016-06-16 17:14:09 -04:00
|
|
|
if (route.path === '') {
|
2016-06-27 23:10:36 -04:00
|
|
|
if ((route.terminal || route.pathMatch === 'full') &&
|
2016-07-25 15:15:07 -04:00
|
|
|
(segmentGroup.hasChildren() || segments.length > 0)) {
|
2016-06-14 17:55:59 -04:00
|
|
|
throw new NoMatch();
|
|
|
|
} else {
|
2016-07-08 17:23:23 -04:00
|
|
|
const params = parent ? parent.params : {};
|
2016-07-25 15:15:07 -04:00
|
|
|
return {consumedSegments: [], lastChild: 0, parameters: params};
|
2016-06-14 17:55:59 -04:00
|
|
|
}
|
|
|
|
}
|
2016-05-23 19:14:23 -04:00
|
|
|
|
2016-06-16 17:14:09 -04:00
|
|
|
const path = route.path;
|
2016-06-14 17:55:59 -04:00
|
|
|
const parts = path.split('/');
|
2016-06-15 12:14:41 -04:00
|
|
|
const posParameters: {[key: string]: any} = {};
|
2016-07-25 15:15:07 -04:00
|
|
|
const consumedSegments: UrlSegment[] = [];
|
2016-06-14 17:55:59 -04:00
|
|
|
|
|
|
|
let currentIndex = 0;
|
|
|
|
|
|
|
|
for (let i = 0; i < parts.length; ++i) {
|
2016-07-25 15:15:07 -04:00
|
|
|
if (currentIndex >= segments.length) throw new NoMatch();
|
|
|
|
const current = segments[currentIndex];
|
2016-06-14 17:55:59 -04:00
|
|
|
|
|
|
|
const p = parts[i];
|
|
|
|
const isPosParam = p.startsWith(':');
|
|
|
|
|
|
|
|
if (!isPosParam && p !== current.path) throw new NoMatch();
|
|
|
|
if (isPosParam) {
|
|
|
|
posParameters[p.substring(1)] = current.path;
|
2016-05-23 19:14:23 -04:00
|
|
|
}
|
2016-07-25 15:15:07 -04:00
|
|
|
consumedSegments.push(current);
|
2016-06-14 17:55:59 -04:00
|
|
|
currentIndex++;
|
|
|
|
}
|
|
|
|
|
2016-06-27 23:10:36 -04:00
|
|
|
if ((route.terminal || route.pathMatch === 'full') &&
|
2016-07-25 15:15:07 -04:00
|
|
|
(segmentGroup.hasChildren() || currentIndex < segments.length)) {
|
2016-06-14 17:55:59 -04:00
|
|
|
throw new NoMatch();
|
2016-05-23 19:14:23 -04:00
|
|
|
}
|
|
|
|
|
2016-07-25 15:15:07 -04:00
|
|
|
const parameters = merge(posParameters, consumedSegments[consumedSegments.length - 1].parameters);
|
|
|
|
return {consumedSegments, lastChild: currentIndex, parameters};
|
2016-05-23 19:14:23 -04:00
|
|
|
}
|
|
|
|
|
2016-06-14 17:55:59 -04:00
|
|
|
function checkOutletNameUniqueness(nodes: TreeNode<ActivatedRouteSnapshot>[]): void {
|
2016-06-15 19:45:19 -04:00
|
|
|
const names: {[k: string]: ActivatedRouteSnapshot} = {};
|
2016-06-14 17:55:59 -04:00
|
|
|
nodes.forEach(n => {
|
|
|
|
let routeWithSameOutletName = names[n.value.outlet];
|
|
|
|
if (routeWithSameOutletName) {
|
2016-06-15 19:45:19 -04:00
|
|
|
const p = routeWithSameOutletName.url.map(s => s.toString()).join('/');
|
2016-06-14 17:55:59 -04:00
|
|
|
const c = n.value.url.map(s => s.toString()).join('/');
|
|
|
|
throw new Error(`Two segments cannot have the same outlet name: '${p}' and '${c}'.`);
|
|
|
|
}
|
|
|
|
names[n.value.outlet] = n.value;
|
|
|
|
});
|
2016-06-24 14:17:17 -04:00
|
|
|
}
|
|
|
|
|
2016-07-25 15:15:07 -04:00
|
|
|
function getSourceSegmentGroup(segmentGroup: UrlSegmentGroup): UrlSegmentGroup {
|
|
|
|
let s = segmentGroup;
|
2016-06-24 14:17:17 -04:00
|
|
|
while (s._sourceSegment) {
|
|
|
|
s = s._sourceSegment;
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2016-07-25 15:15:07 -04:00
|
|
|
function getPathIndexShift(segmentGroup: UrlSegmentGroup): number {
|
|
|
|
let s = segmentGroup;
|
|
|
|
let res = (s._segmentIndexShift ? s._segmentIndexShift : 0);
|
2016-06-24 14:17:17 -04:00
|
|
|
while (s._sourceSegment) {
|
|
|
|
s = s._sourceSegment;
|
2016-07-25 15:15:07 -04:00
|
|
|
res += (s._segmentIndexShift ? s._segmentIndexShift : 0);
|
2016-06-24 14:17:17 -04:00
|
|
|
}
|
2016-07-18 17:53:13 -04:00
|
|
|
return res - 1;
|
2016-06-24 14:17:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function split(
|
2016-07-25 15:15:07 -04:00
|
|
|
segmentGroup: UrlSegmentGroup, consumedSegments: UrlSegment[], slicedSegments: UrlSegment[],
|
2016-06-24 14:17:17 -04:00
|
|
|
config: Route[]) {
|
2016-07-25 15:15:07 -04:00
|
|
|
if (slicedSegments.length > 0 &&
|
|
|
|
containsEmptyPathMatchesWithNamedOutlets(segmentGroup, slicedSegments, config)) {
|
|
|
|
const s = new UrlSegmentGroup(
|
|
|
|
consumedSegments, createChildrenForEmptyPaths(
|
|
|
|
segmentGroup, consumedSegments, config,
|
|
|
|
new UrlSegmentGroup(slicedSegments, segmentGroup.children)));
|
|
|
|
s._sourceSegment = segmentGroup;
|
|
|
|
s._segmentIndexShift = consumedSegments.length;
|
|
|
|
return {segmentGroup: s, slicedSegments: []};
|
|
|
|
|
|
|
|
} else if (
|
|
|
|
slicedSegments.length === 0 &&
|
|
|
|
containsEmptyPathMatches(segmentGroup, slicedSegments, config)) {
|
|
|
|
const s = new UrlSegmentGroup(
|
|
|
|
segmentGroup.segments, addEmptyPathsToChildrenIfNeeded(
|
|
|
|
segmentGroup, slicedSegments, config, segmentGroup.children));
|
|
|
|
s._sourceSegment = segmentGroup;
|
|
|
|
s._segmentIndexShift = consumedSegments.length;
|
|
|
|
return {segmentGroup: s, slicedSegments};
|
2016-06-24 14:17:17 -04:00
|
|
|
|
|
|
|
} else {
|
2016-07-25 15:15:07 -04:00
|
|
|
const s = new UrlSegmentGroup(segmentGroup.segments, segmentGroup.children);
|
|
|
|
s._sourceSegment = segmentGroup;
|
|
|
|
s._segmentIndexShift = consumedSegments.length;
|
|
|
|
return {segmentGroup: s, slicedSegments};
|
2016-06-24 14:17:17 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function addEmptyPathsToChildrenIfNeeded(
|
2016-07-25 15:15:07 -04:00
|
|
|
segmentGroup: UrlSegmentGroup, slicedSegments: UrlSegment[], routes: Route[],
|
|
|
|
children: {[name: string]: UrlSegmentGroup}): {[name: string]: UrlSegmentGroup} {
|
|
|
|
const res: {[name: string]: UrlSegmentGroup} = {};
|
2016-06-24 14:17:17 -04:00
|
|
|
for (let r of routes) {
|
2016-07-25 15:15:07 -04:00
|
|
|
if (emptyPathMatch(segmentGroup, slicedSegments, r) && !children[getOutlet(r)]) {
|
|
|
|
const s = new UrlSegmentGroup([], {});
|
|
|
|
s._sourceSegment = segmentGroup;
|
|
|
|
s._segmentIndexShift = segmentGroup.segments.length;
|
2016-06-24 14:17:17 -04:00
|
|
|
res[getOutlet(r)] = s;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return merge(children, res);
|
|
|
|
}
|
|
|
|
|
|
|
|
function createChildrenForEmptyPaths(
|
2016-07-25 15:15:07 -04:00
|
|
|
segmentGroup: UrlSegmentGroup, consumedSegments: UrlSegment[], routes: Route[],
|
|
|
|
primarySegment: UrlSegmentGroup): {[name: string]: UrlSegmentGroup} {
|
|
|
|
const res: {[name: string]: UrlSegmentGroup} = {};
|
2016-06-24 14:17:17 -04:00
|
|
|
res[PRIMARY_OUTLET] = primarySegment;
|
2016-07-25 15:15:07 -04:00
|
|
|
primarySegment._sourceSegment = segmentGroup;
|
|
|
|
primarySegment._segmentIndexShift = consumedSegments.length;
|
2016-06-24 14:17:17 -04:00
|
|
|
|
|
|
|
for (let r of routes) {
|
2016-07-22 21:32:26 -04:00
|
|
|
if (r.path === '' && getOutlet(r) !== PRIMARY_OUTLET) {
|
2016-07-25 15:15:07 -04:00
|
|
|
const s = new UrlSegmentGroup([], {});
|
|
|
|
s._sourceSegment = segmentGroup;
|
|
|
|
s._segmentIndexShift = consumedSegments.length;
|
2016-06-24 14:17:17 -04:00
|
|
|
res[getOutlet(r)] = s;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
function containsEmptyPathMatchesWithNamedOutlets(
|
2016-07-25 15:15:07 -04:00
|
|
|
segmentGroup: UrlSegmentGroup, slicedSegments: UrlSegment[], routes: Route[]): boolean {
|
2016-06-24 14:17:17 -04:00
|
|
|
return routes
|
2016-07-25 15:15:07 -04:00
|
|
|
.filter(
|
|
|
|
r => emptyPathMatch(segmentGroup, slicedSegments, r) &&
|
|
|
|
getOutlet(r) !== PRIMARY_OUTLET)
|
2016-06-24 14:17:17 -04:00
|
|
|
.length > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
function containsEmptyPathMatches(
|
2016-07-25 15:15:07 -04:00
|
|
|
segmentGroup: UrlSegmentGroup, slicedSegments: UrlSegment[], routes: Route[]): boolean {
|
|
|
|
return routes.filter(r => emptyPathMatch(segmentGroup, slicedSegments, r)).length > 0;
|
2016-06-24 14:17:17 -04:00
|
|
|
}
|
|
|
|
|
2016-07-25 15:15:07 -04:00
|
|
|
function emptyPathMatch(
|
|
|
|
segmentGroup: UrlSegmentGroup, slicedSegments: UrlSegment[], r: Route): boolean {
|
|
|
|
if ((segmentGroup.hasChildren() || slicedSegments.length > 0) &&
|
|
|
|
(r.terminal || r.pathMatch === 'full'))
|
2016-06-27 23:10:36 -04:00
|
|
|
return false;
|
2016-06-24 14:17:17 -04:00
|
|
|
return r.path === '' && r.redirectTo === undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getOutlet(route: Route): string {
|
|
|
|
return route.outlet ? route.outlet : PRIMARY_OUTLET;
|
2016-06-27 17:00:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function getData(route: Route): Data {
|
|
|
|
return route.data ? route.data : {};
|
|
|
|
}
|
|
|
|
|
|
|
|
function getResolve(route: Route): ResolveData {
|
|
|
|
return route.resolve ? route.resolve : {};
|
2016-05-26 19:51:44 -04:00
|
|
|
}
|