cleanup(router): enable noImplicitAny and noImplicntReturns
This commit is contained in:
parent
cdbf67ee05
commit
4450e7b246
|
@ -1,4 +1,5 @@
|
|||
import {Observable} from 'rxjs/Observable';
|
||||
import {Observer} from 'rxjs/Observer';
|
||||
import {of } from 'rxjs/observable/of';
|
||||
|
||||
import {Route, RouterConfig} from './config';
|
||||
|
@ -21,9 +22,10 @@ export function applyRedirects(urlTree: UrlTree, config: RouterConfig): Observab
|
|||
urlTree, new UrlSegment([], {[PRIMARY_OUTLET]: new UrlSegment(e.paths, {})}));
|
||||
} else if (e instanceof NoMatch) {
|
||||
return new Observable<UrlTree>(
|
||||
obs => obs.error(new Error(`Cannot match any routes: '${e.segment}'`)));
|
||||
(obs: Observer<UrlTree>) =>
|
||||
obs.error(new Error(`Cannot match any routes: '${e.segment}'`)));
|
||||
} else {
|
||||
return new Observable<UrlTree>(obs => obs.error(e));
|
||||
return new Observable<UrlTree>((obs: Observer<UrlTree>) => obs.error(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -128,7 +130,11 @@ function matchPathsWithParamsAgainstRoute(
|
|||
}
|
||||
}
|
||||
|
||||
function match(segment: UrlSegment, route: Route, paths: UrlPathWithParams[]) {
|
||||
function match(segment: UrlSegment, route: Route, paths: UrlPathWithParams[]): {
|
||||
consumedPaths: UrlPathWithParams[],
|
||||
lastChild: number,
|
||||
positionalParamSegments: {[k: string]: UrlPathWithParams}
|
||||
} {
|
||||
if (route.index || route.path === '' || route.path === '/') {
|
||||
if (route.terminal && (Object.keys(segment.children).length > 0 || paths.length > 0)) {
|
||||
throw new NoMatch();
|
||||
|
@ -139,8 +145,8 @@ function match(segment: UrlSegment, route: Route, paths: UrlPathWithParams[]) {
|
|||
|
||||
const path = route.path.startsWith('/') ? route.path.substring(1) : route.path;
|
||||
const parts = path.split('/');
|
||||
const positionalParamSegments = {};
|
||||
const consumedPaths = [];
|
||||
const positionalParamSegments: {[k: string]: UrlPathWithParams} = {};
|
||||
const consumedPaths: UrlPathWithParams[] = [];
|
||||
|
||||
let currentIndex = 0;
|
||||
|
||||
|
|
|
@ -13,7 +13,9 @@ export const ROUTER_OPTIONS = new OpaqueToken('ROUTER_OPTIONS');
|
|||
export interface ExtraOptions { enableTracing?: boolean; }
|
||||
|
||||
export function setupRouter(
|
||||
ref, resolver, urlSerializer, outletMap, location, injector, config, opts) {
|
||||
ref: ApplicationRef, resolver: ComponentResolver, urlSerializer: UrlSerializer,
|
||||
outletMap: RouterOutletMap, location: Location, injector: Injector, config: RouterConfig,
|
||||
opts: ExtraOptions) {
|
||||
if (ref.componentTypes.length == 0) {
|
||||
throw new Error('Bootstrap at least one component before injecting Router.');
|
||||
}
|
||||
|
@ -38,15 +40,15 @@ export function setupRouterInitializer(injector: Injector) {
|
|||
// https://github.com/angular/angular/issues/9101
|
||||
// Delay the router instantiation to avoid circular dependency (ApplicationRef ->
|
||||
// APP_INITIALIZER -> Router)
|
||||
setTimeout(_ => {
|
||||
setTimeout(() => {
|
||||
const appRef = injector.get(ApplicationRef);
|
||||
if (appRef.componentTypes.length == 0) {
|
||||
appRef.registerBootstrapListener((_) => { injector.get(Router).initialNavigation(); });
|
||||
appRef.registerBootstrapListener(() => { injector.get(Router).initialNavigation(); });
|
||||
} else {
|
||||
injector.get(Router).initialNavigation();
|
||||
}
|
||||
}, 0);
|
||||
return _ => null;
|
||||
return (): any => null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -83,7 +85,7 @@ export function provideRouter(_config: RouterConfig, _opts: ExtraOptions): any[]
|
|||
},
|
||||
|
||||
RouterOutletMap,
|
||||
{provide: ActivatedRoute, useFactory: (r) => r.routerState.root, deps: [Router]},
|
||||
{provide: ActivatedRoute, useFactory: (r: Router) => r.routerState.root, deps: [Router]},
|
||||
|
||||
// Trigger initial navigation
|
||||
{provide: APP_INITIALIZER, multi: true, useFactory: setupRouterInitializer, deps: [Injector]}
|
||||
|
|
|
@ -39,11 +39,11 @@ function tree(
|
|||
function replaceSegment(
|
||||
current: UrlSegment, oldSegment: UrlSegment, newSegment: UrlSegment): UrlSegment {
|
||||
const children: {[key: string]: UrlSegment} = {};
|
||||
forEach(current.children, (c, k) => {
|
||||
forEach(current.children, (c: UrlSegment, outletName: string) => {
|
||||
if (c === oldSegment) {
|
||||
children[k] = newSegment;
|
||||
children[outletName] = newSegment;
|
||||
} else {
|
||||
children[k] = replaceSegment(c, oldSegment, newSegment);
|
||||
children[outletName] = replaceSegment(c, oldSegment, newSegment);
|
||||
}
|
||||
});
|
||||
return new UrlSegment(current.pathsWithParams, children);
|
||||
|
@ -66,7 +66,7 @@ function normalizeCommands(commands: any[]): NormalizedNavigationCommands {
|
|||
|
||||
let numberOfDoubleDots = 0;
|
||||
let isAbsolute = false;
|
||||
const res = [];
|
||||
const res: any[] = [];
|
||||
|
||||
for (let i = 0; i < commands.length; ++i) {
|
||||
const c = commands[i];
|
||||
|
@ -164,7 +164,7 @@ function updateSegmentChildren(
|
|||
const outlet = getOutlet(commands);
|
||||
const children: {[key: string]: UrlSegment} = {};
|
||||
children[outlet] = updateSegment(segment.children[outlet], startIndex, commands);
|
||||
forEach(segment.children, (child, childOutlet) => {
|
||||
forEach(segment.children, (child: UrlSegment, childOutlet: string) => {
|
||||
if (childOutlet !== outlet) {
|
||||
children[childOutlet] = child;
|
||||
}
|
||||
|
@ -224,7 +224,7 @@ function createNewSegment(segment: UrlSegment, startIndex: number, commands: any
|
|||
|
||||
function stringify(params: {[key: string]: any}): {[key: string]: string} {
|
||||
const res: {[key: string]: string} = {};
|
||||
forEach(params, (v, k) => res[k] = `${v}`);
|
||||
forEach(params, (v: any, k: string) => res[k] = `${v}`);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import {Type} from '@angular/core';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
import {Observer} from 'rxjs/Observer';
|
||||
import {of } from 'rxjs/observable/of';
|
||||
|
||||
import {Route, RouterConfig} from './config';
|
||||
|
@ -25,9 +26,11 @@ export function recognize(
|
|||
} catch (e) {
|
||||
if (e instanceof NoMatch) {
|
||||
return new Observable<RouterStateSnapshot>(
|
||||
obs => obs.error(new Error(`Cannot match any routes: '${e.segment}'`)));
|
||||
(obs: Observer<RouterStateSnapshot>) =>
|
||||
obs.error(new Error(`Cannot match any routes: '${e.segment}'`)));
|
||||
} else {
|
||||
return new Observable<RouterStateSnapshot>(obs => obs.error(e));
|
||||
return new Observable<RouterStateSnapshot>(
|
||||
(obs: Observer<RouterStateSnapshot>) => obs.error(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -119,7 +122,7 @@ function match(segment: UrlSegment, route: Route, paths: UrlPathWithParams[]) {
|
|||
const path = route.path.startsWith('/') ? route.path.substring(1) : route.path;
|
||||
const parts = path.split('/');
|
||||
const posParameters: {[key: string]: any} = {};
|
||||
const consumedPaths = [];
|
||||
const consumedPaths: UrlPathWithParams[] = [];
|
||||
|
||||
let currentIndex = 0;
|
||||
|
||||
|
@ -147,11 +150,11 @@ function match(segment: UrlSegment, route: Route, paths: UrlPathWithParams[]) {
|
|||
}
|
||||
|
||||
function checkOutletNameUniqueness(nodes: TreeNode<ActivatedRouteSnapshot>[]): void {
|
||||
const names = {};
|
||||
const names: {[k: string]: ActivatedRouteSnapshot} = {};
|
||||
nodes.forEach(n => {
|
||||
let routeWithSameOutletName = names[n.value.outlet];
|
||||
if (routeWithSameOutletName) {
|
||||
const p = routeWithSameOutletName.urlSegments.map(s => s.toString()).join('/');
|
||||
const p = routeWithSameOutletName.url.map(s => s.toString()).join('/');
|
||||
const c = n.value.url.map(s => s.toString()).join('/');
|
||||
throw new Error(`Two segments cannot have the same outlet name: '${p}' and '${c}'.`);
|
||||
}
|
||||
|
|
|
@ -265,8 +265,8 @@ export class Router {
|
|||
}
|
||||
|
||||
return new Promise((resolvePromise, rejectPromise) => {
|
||||
let updatedUrl;
|
||||
let state;
|
||||
let updatedUrl: UrlTree;
|
||||
let state: RouterState;
|
||||
applyRedirects(url, this.config)
|
||||
.mergeMap(u => {
|
||||
updatedUrl = u;
|
||||
|
@ -293,7 +293,7 @@ export class Router {
|
|||
.check(this.outletMap);
|
||||
|
||||
})
|
||||
.forEach((shouldActivate) => {
|
||||
.forEach((shouldActivate: boolean) => {
|
||||
if (!shouldActivate || id !== this.navigationId) {
|
||||
this.routerEvents.next(new NavigationCancel(id, this.serializeUrl(url)));
|
||||
return Promise.resolve(false);
|
||||
|
@ -311,6 +311,7 @@ export class Router {
|
|||
this.location.go(path);
|
||||
}
|
||||
}
|
||||
return Promise.resolve(true);
|
||||
})
|
||||
.then(
|
||||
() => {
|
||||
|
@ -335,7 +336,7 @@ class CanDeactivate {
|
|||
}
|
||||
|
||||
class GuardChecks {
|
||||
private checks = [];
|
||||
private checks: Array<CanActivate|CanDeactivate> = [];
|
||||
constructor(
|
||||
private future: RouterStateSnapshot, private curr: RouterStateSnapshot,
|
||||
private injector: Injector) {}
|
||||
|
@ -368,7 +369,9 @@ class GuardChecks {
|
|||
this.traverseRoutes(c, prevChildren[c.value.outlet], outletMap);
|
||||
delete prevChildren[c.value.outlet];
|
||||
});
|
||||
forEach(prevChildren, (v, k) => this.deactivateOutletAndItChildren(v, outletMap._outlets[k]));
|
||||
forEach(
|
||||
prevChildren,
|
||||
(v: any, k: string) => this.deactivateOutletAndItChildren(v, outletMap._outlets[k]));
|
||||
}
|
||||
|
||||
traverseRoutes(
|
||||
|
@ -392,7 +395,7 @@ class GuardChecks {
|
|||
|
||||
private deactivateOutletAndItChildren(route: ActivatedRouteSnapshot, outlet: RouterOutlet): void {
|
||||
if (outlet && outlet.isActivated) {
|
||||
forEach(outlet.outletMap._outlets, (v, k) => {
|
||||
forEach(outlet.outletMap._outlets, (v: RouterOutlet) => {
|
||||
if (v.isActivated) {
|
||||
this.deactivateOutletAndItChildren(v.activatedRoute.snapshot, v);
|
||||
}
|
||||
|
@ -461,7 +464,9 @@ class ActivateRoutes {
|
|||
this.activateRoutes(c, prevChildren[c.value.outlet], outletMap);
|
||||
delete prevChildren[c.value.outlet];
|
||||
});
|
||||
forEach(prevChildren, (v, k) => this.deactivateOutletAndItChildren(outletMap._outlets[k]));
|
||||
forEach(
|
||||
prevChildren,
|
||||
(v: any, k: string) => this.deactivateOutletAndItChildren(outletMap._outlets[k]));
|
||||
}
|
||||
|
||||
activateRoutes(
|
||||
|
@ -495,7 +500,8 @@ class ActivateRoutes {
|
|||
|
||||
private deactivateOutletAndItChildren(outlet: RouterOutlet): void {
|
||||
if (outlet && outlet.isActivated) {
|
||||
forEach(outlet.outletMap._outlets, (v, k) => this.deactivateOutletAndItChildren(v));
|
||||
forEach(
|
||||
outlet.outletMap._outlets, (v: RouterOutlet) => this.deactivateOutletAndItChildren(v));
|
||||
outlet.deactivate();
|
||||
}
|
||||
}
|
||||
|
@ -512,7 +518,7 @@ function pushQueryParamsAndFragment(state: RouterState): void {
|
|||
}
|
||||
|
||||
function nodeChildrenAsMap(node: TreeNode<any>) {
|
||||
return node ? node.children.reduce((m, c) => {
|
||||
return node ? node.children.reduce((m: any, c: TreeNode<any>) => {
|
||||
m[c.value.outlet] = c;
|
||||
return m;
|
||||
}, {}) : {};
|
||||
|
|
|
@ -43,8 +43,8 @@ export function serializePaths(segment: UrlSegment): string {
|
|||
function serializeSegment(segment: UrlSegment, root: boolean): string {
|
||||
if (segment.children[PRIMARY_OUTLET] && root) {
|
||||
const primary = serializeSegment(segment.children[PRIMARY_OUTLET], false);
|
||||
const children = [];
|
||||
forEach(segment.children, (v, k) => {
|
||||
const children: string[] = [];
|
||||
forEach(segment.children, (v: UrlSegment, k: string) => {
|
||||
if (k !== PRIMARY_OUTLET) {
|
||||
children.push(`${k}:${serializeSegment(v, false)}`);
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ function serializeSegment(segment: UrlSegment, root: boolean): string {
|
|||
}
|
||||
} else if (segment.children[PRIMARY_OUTLET] && !root) {
|
||||
const children = [serializeSegment(segment.children[PRIMARY_OUTLET], false)];
|
||||
forEach(segment.children, (v, k) => {
|
||||
forEach(segment.children, (v: UrlSegment, k: string) => {
|
||||
if (k !== PRIMARY_OUTLET) {
|
||||
children.push(`${k}:${serializeSegment(v, false)}`);
|
||||
}
|
||||
|
@ -71,15 +71,15 @@ function serializeChildren(segment: UrlSegment) {
|
|||
if (segment.children[PRIMARY_OUTLET]) {
|
||||
const primary = serializePaths(segment.children[PRIMARY_OUTLET]);
|
||||
|
||||
const secondary = [];
|
||||
forEach(segment.children, (v, k) => {
|
||||
const secondary: string[] = [];
|
||||
forEach(segment.children, (v: UrlSegment, k: string) => {
|
||||
if (k !== PRIMARY_OUTLET) {
|
||||
secondary.push(`${k}:${serializePaths(v)}${serializeChildren(v)}`);
|
||||
}
|
||||
});
|
||||
const secondaryStr = secondary.length > 0 ? `(${secondary.join('//')})` : '';
|
||||
const primaryChildren = serializeChildren(segment.children[PRIMARY_OUTLET]);
|
||||
const primaryChildrenStr = primaryChildren ? `/${primaryChildren}` : '';
|
||||
const primaryChildrenStr: string = primaryChildren ? `/${primaryChildren}` : '';
|
||||
return `${primary}${secondaryStr}${primaryChildrenStr}`;
|
||||
} else {
|
||||
return '';
|
||||
|
@ -103,7 +103,7 @@ class Pair<A, B> {
|
|||
constructor(public first: A, public second: B) {}
|
||||
}
|
||||
function pairs<T>(obj: {[key: string]: T}): Pair<string, T>[] {
|
||||
const res = [];
|
||||
const res: Pair<string, T>[] = [];
|
||||
for (let prop in obj) {
|
||||
if (obj.hasOwnProperty(prop)) {
|
||||
res.push(new Pair<string, T>(prop, obj[prop]));
|
||||
|
@ -260,7 +260,7 @@ class UrlParser {
|
|||
|
||||
while (!this.peekStartsWith(')') && this.remaining.length > 0) {
|
||||
let path = matchPathWithParams(this.remaining);
|
||||
let outletName;
|
||||
let outletName: string;
|
||||
if (path.indexOf(':') > -1) {
|
||||
outletName = path.substr(0, path.indexOf(':'));
|
||||
this.capture(outletName);
|
||||
|
|
|
@ -71,7 +71,7 @@ export class UrlSegment {
|
|||
public parent: UrlSegment = null;
|
||||
constructor(
|
||||
public pathsWithParams: UrlPathWithParams[], public children: {[key: string]: UrlSegment}) {
|
||||
forEach(children, (v, k) => v.parent = this);
|
||||
forEach(children, (v: any, k: any) => v.parent = this);
|
||||
}
|
||||
|
||||
toString(): string { return serializePaths(this); }
|
||||
|
@ -102,12 +102,12 @@ export function equalPath(a: UrlPathWithParams[], b: UrlPathWithParams[]): boole
|
|||
export function mapChildren(segment: UrlSegment, fn: (v: UrlSegment, k: string) => UrlSegment):
|
||||
{[name: string]: UrlSegment} {
|
||||
const newChildren: {[name: string]: UrlSegment} = {};
|
||||
forEach(segment.children, (child, childOutlet) => {
|
||||
forEach(segment.children, (child: UrlSegment, childOutlet: string) => {
|
||||
if (childOutlet === PRIMARY_OUTLET) {
|
||||
newChildren[childOutlet] = fn(child, childOutlet);
|
||||
}
|
||||
});
|
||||
forEach(segment.children, (child, childOutlet) => {
|
||||
forEach(segment.children, (child: UrlSegment, childOutlet: string) => {
|
||||
if (childOutlet !== PRIMARY_OUTLET) {
|
||||
newChildren[childOutlet] = fn(child, childOutlet);
|
||||
}
|
||||
|
@ -117,13 +117,13 @@ export function mapChildren(segment: UrlSegment, fn: (v: UrlSegment, k: string)
|
|||
|
||||
export function mapChildrenIntoArray<T>(
|
||||
segment: UrlSegment, fn: (v: UrlSegment, k: string) => T[]): T[] {
|
||||
let res = [];
|
||||
forEach(segment.children, (child, childOutlet) => {
|
||||
let res: T[] = [];
|
||||
forEach(segment.children, (child: UrlSegment, childOutlet: string) => {
|
||||
if (childOutlet === PRIMARY_OUTLET) {
|
||||
res = res.concat(fn(child, childOutlet));
|
||||
}
|
||||
});
|
||||
forEach(segment.children, (child, childOutlet) => {
|
||||
forEach(segment.children, (child: UrlSegment, childOutlet: string) => {
|
||||
if (childOutlet !== PRIMARY_OUTLET) {
|
||||
res = res.concat(fn(child, childOutlet));
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
export function shallowEqual(a: {[x: string]: any}, b: {[x: string]: any}): boolean {
|
||||
var k1 = Object.keys(a);
|
||||
var k2 = Object.keys(b);
|
||||
const k1 = Object.keys(a);
|
||||
const k2 = Object.keys(b);
|
||||
if (k1.length != k2.length) {
|
||||
return false;
|
||||
}
|
||||
var key;
|
||||
for (var i = 0; i < k1.length; i++) {
|
||||
let key: string;
|
||||
for (let i = 0; i < k1.length; i++) {
|
||||
key = k1[i];
|
||||
if (a[key] !== b[key]) {
|
||||
return false;
|
||||
|
@ -15,7 +15,7 @@ export function shallowEqual(a: {[x: string]: any}, b: {[x: string]: any}): bool
|
|||
}
|
||||
|
||||
export function flatten<T>(a: T[][]): T[] {
|
||||
const target = [];
|
||||
const target: T[] = [];
|
||||
for (let i = 0; i < a.length; ++i) {
|
||||
for (let j = 0; j < a[i].length; ++j) {
|
||||
target.push(a[i][j]);
|
||||
|
|
|
@ -8,7 +8,7 @@ describe('applyRedirects', () => {
|
|||
it("should return the same url tree when no redirects", () => {
|
||||
checkRedirect([
|
||||
{path: 'a', component: ComponentA, children: [{path: 'b', component: ComponentB}]}
|
||||
], "/a/b", t => {
|
||||
], "/a/b", (t:UrlTree) => {
|
||||
compareTrees(t, tree('/a/b'));
|
||||
});
|
||||
});
|
||||
|
@ -17,7 +17,7 @@ describe('applyRedirects', () => {
|
|||
checkRedirect([
|
||||
{path: 'a/b', redirectTo: 'a/b/c'},
|
||||
{path: '**', component: ComponentC}
|
||||
], "/a/b", t => {
|
||||
], "/a/b", (t:UrlTree) => {
|
||||
compareTrees(t, tree('/a/b/c'));
|
||||
});
|
||||
});
|
||||
|
@ -26,7 +26,7 @@ describe('applyRedirects', () => {
|
|||
checkRedirect([
|
||||
{path: 'a/:aid/b/:bid', redirectTo: 'newa/:aid/newb/:bid'},
|
||||
{path: '**', component: ComponentC}
|
||||
], "/a/1/b/2", t => {
|
||||
], "/a/1/b/2", (t:UrlTree) => {
|
||||
compareTrees(t, tree('/newa/1/newb/2'));
|
||||
});
|
||||
});
|
||||
|
@ -43,7 +43,7 @@ describe('applyRedirects', () => {
|
|||
checkRedirect([
|
||||
{path: 'a/:id', redirectTo: 'd/a/:id/e'},
|
||||
{path: '**', component: ComponentC}
|
||||
], "/a;p1=1/1;p2=2", t => {
|
||||
], "/a;p1=1/1;p2=2", (t:UrlTree) => {
|
||||
compareTrees(t, tree('/d/a;p1=1/1;p2=2/e'));
|
||||
});
|
||||
});
|
||||
|
@ -53,7 +53,7 @@ describe('applyRedirects', () => {
|
|||
{path: 'a/:id', redirectTo: 'd/a/:id/e'},
|
||||
{path: 'c/d', component: ComponentA, outlet: 'aux'},
|
||||
{path: '**', component: ComponentC}
|
||||
], "/a/1(aux:c/d)", t => {
|
||||
], "/a/1(aux:c/d)", (t:UrlTree) => {
|
||||
compareTrees(t, tree('/d/a/1/e(aux:c/d)'));
|
||||
});
|
||||
});
|
||||
|
@ -63,7 +63,7 @@ describe('applyRedirects', () => {
|
|||
{path: 'a/:id', component: ComponentA},
|
||||
{path: 'c/d', redirectTo: 'f/c/d/e', outlet: 'aux'},
|
||||
{path: '**', component: ComponentC, outlet: 'aux'}
|
||||
], "/a/1(aux:c/d)", t => {
|
||||
], "/a/1(aux:c/d)", (t:UrlTree) => {
|
||||
compareTrees(t, tree('/a/1(aux:f/c/d/e)'));
|
||||
});
|
||||
});
|
||||
|
@ -74,7 +74,7 @@ describe('applyRedirects', () => {
|
|||
{path: 'b', component: ComponentB},
|
||||
]},
|
||||
{path: 'c', redirectTo: 'a'}
|
||||
], "c/b", t => {
|
||||
], "c/b", (t:UrlTree) => {
|
||||
compareTrees(t, tree('a/b'));
|
||||
});
|
||||
});
|
||||
|
@ -85,7 +85,7 @@ describe('applyRedirects', () => {
|
|||
{path: 'b', component: ComponentB},
|
||||
]},
|
||||
{path: '', redirectTo: 'a'}
|
||||
], "b", t => {
|
||||
], "b", (t:UrlTree) => {
|
||||
compareTrees(t, tree('a/b'));
|
||||
});
|
||||
});
|
||||
|
@ -96,7 +96,7 @@ describe('applyRedirects', () => {
|
|||
{path: 'b', component: ComponentB},
|
||||
]},
|
||||
{path: '', redirectTo: '/a/b'}
|
||||
], "", t => {
|
||||
], "", (t:UrlTree) => {
|
||||
compareTrees(t, tree('a/b'));
|
||||
});
|
||||
});
|
||||
|
@ -108,7 +108,7 @@ describe('applyRedirects', () => {
|
|||
{path: '', redirectTo: 'b'}
|
||||
]},
|
||||
{path: '', redirectTo: 'a'}
|
||||
], "", t => {
|
||||
], "", (t:UrlTree) => {
|
||||
compareTrees(t, tree('a/b'));
|
||||
});
|
||||
});
|
||||
|
@ -120,7 +120,7 @@ describe('applyRedirects', () => {
|
|||
{path: '', redirectTo: 'b'}
|
||||
]},
|
||||
{path: 'a', redirectTo: ''}
|
||||
], "a", t => {
|
||||
], "a", (t:UrlTree) => {
|
||||
compareTrees(t, tree('b'));
|
||||
});
|
||||
});
|
||||
|
@ -144,7 +144,7 @@ describe('applyRedirects', () => {
|
|||
checkRedirect([
|
||||
{path: '404', component: ComponentA},
|
||||
{path: '**', redirectTo: '/404'},
|
||||
], "/a/1(aux:c/d)", t => {
|
||||
], "/a/1(aux:c/d)", (t:UrlTree) => {
|
||||
compareTrees(t, tree('/404'));
|
||||
});
|
||||
});
|
||||
|
@ -155,7 +155,7 @@ describe('applyRedirects', () => {
|
|||
{path: 'b/:id', redirectTo: '/global/:id'}
|
||||
]},
|
||||
{path: '**', component: ComponentC}
|
||||
], "/a/b/1", t => {
|
||||
], "/a/b/1", (t:UrlTree) => {
|
||||
compareTrees(t, tree('/global/1'));
|
||||
});
|
||||
});
|
||||
|
|
|
@ -56,7 +56,7 @@ function advanceNode(node: TreeNode<ActivatedRoute>): void {
|
|||
}
|
||||
|
||||
function createState(config: RouterConfig, url: string): RouterStateSnapshot {
|
||||
let res;
|
||||
let res: RouterStateSnapshot;
|
||||
recognize(RootComponent, config, tree(url), url).forEach(s => res = s);
|
||||
return res;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import {DefaultUrlSerializer} from '../src/url_serializer';
|
||||
import {UrlTree} from '../src/url_tree';
|
||||
import {Params, PRIMARY_OUTLET} from '../src/shared';
|
||||
import {ActivatedRouteSnapshot} from '../src/router_state';
|
||||
import {ActivatedRouteSnapshot, RouterStateSnapshot} from '../src/router_state';
|
||||
import {RouterConfig} from '../src/config';
|
||||
import {recognize} from '../src/recognize';
|
||||
|
||||
|
@ -11,7 +11,7 @@ describe('recognize', () => {
|
|||
{
|
||||
path: 'a', component: ComponentA
|
||||
}
|
||||
], "a", s => {
|
||||
], "a", (s:RouterStateSnapshot) => {
|
||||
checkActivatedRoute(s.root, "", {}, RootComponent);
|
||||
checkActivatedRoute(s.firstChild(s.root), "a", {}, ComponentA);
|
||||
});
|
||||
|
@ -22,7 +22,7 @@ describe('recognize', () => {
|
|||
{ path: 'a', component: ComponentA },
|
||||
{ path: 'b', component: ComponentB, outlet: 'left' },
|
||||
{ path: 'c', component: ComponentC, outlet: 'right' }
|
||||
], "a(left:b//right:c)", s => {
|
||||
], "a(left:b//right:c)", (s:RouterStateSnapshot) => {
|
||||
const c = s.children(s.root);
|
||||
checkActivatedRoute(c[0], "a", {}, ComponentA);
|
||||
checkActivatedRoute(c[1], "b", {}, ComponentB, 'left');
|
||||
|
@ -58,7 +58,7 @@ describe('recognize', () => {
|
|||
{ path: '/a/b', component: ComponentA, children: [
|
||||
{path: 'c', component: ComponentC}
|
||||
] },
|
||||
], url, "a/b/c").subscribe(s => {
|
||||
], url, "a/b/c").subscribe((s:RouterStateSnapshot) => {
|
||||
expect(s.root._urlSegment).toBe(url.root);
|
||||
expect(s.root._lastPathIndex).toBe(-1);
|
||||
|
||||
|
@ -76,7 +76,7 @@ describe('recognize', () => {
|
|||
checkRecognize([
|
||||
{path: 'a', component: ComponentA, children: [{path: ':id', component: ComponentB}]},
|
||||
{path: 'a/:id', component: ComponentC}
|
||||
], "a/paramA", s => {
|
||||
], "a/paramA", (s:RouterStateSnapshot) => {
|
||||
checkActivatedRoute(s.root, "", {}, RootComponent);
|
||||
checkActivatedRoute(s.firstChild(s.root), "a", {}, ComponentA);
|
||||
checkActivatedRoute(s.firstChild(<any>s.firstChild(s.root)), "paramA", {id: 'paramA'}, ComponentB);
|
||||
|
@ -85,7 +85,7 @@ describe('recognize', () => {
|
|||
checkRecognize([
|
||||
{path: 'a', component: ComponentA},
|
||||
{path: 'a/:id', component: ComponentC}
|
||||
], "a/paramA", s => {
|
||||
], "a/paramA", (s:RouterStateSnapshot) => {
|
||||
checkActivatedRoute(s.root, "", {}, RootComponent);
|
||||
checkActivatedRoute(s.firstChild(s.root), "a/paramA", {id: 'paramA'}, ComponentC);
|
||||
});
|
||||
|
@ -96,7 +96,7 @@ describe('recognize', () => {
|
|||
{ path: 'a', component: ComponentA },
|
||||
{ path: 'b', component: ComponentB, outlet: 'left' },
|
||||
{ path: 'b', component: ComponentC, outlet: 'right' }
|
||||
], "a(right:b)", s => {
|
||||
], "a(right:b)", (s:RouterStateSnapshot) => {
|
||||
const c = s.children(s.root);
|
||||
checkActivatedRoute(c[0], "a", {}, ComponentA);
|
||||
checkActivatedRoute(c[1], "b", {}, ComponentC, 'right');
|
||||
|
@ -108,7 +108,7 @@ describe('recognize', () => {
|
|||
{ path: 'a', component: ComponentA },
|
||||
{ path: 'b', component: ComponentB, outlet: 'left' },
|
||||
{ path: 'c', component: ComponentC, outlet: 'right' }
|
||||
], "a(left:b(right:c))", s => {
|
||||
], "a(left:b(right:c))", (s:RouterStateSnapshot) => {
|
||||
const c = s.children(s.root);
|
||||
checkActivatedRoute(c[0], "a", {}, ComponentA);
|
||||
checkActivatedRoute(c[1], "b", {}, ComponentB, 'left');
|
||||
|
@ -122,7 +122,7 @@ describe('recognize', () => {
|
|||
{ path: 'b', component: ComponentB },
|
||||
{ path: 'c', component: ComponentC, outlet: 'left' }
|
||||
] },
|
||||
], "a/(b//left:c)", s => {
|
||||
], "a/(b//left:c)", (s:RouterStateSnapshot) => {
|
||||
const c = s.children(<any>s.firstChild(s.root));
|
||||
checkActivatedRoute(c[0], "b", {}, ComponentB, PRIMARY_OUTLET);
|
||||
checkActivatedRoute(c[1], "c", {}, ComponentC, 'left');
|
||||
|
@ -134,7 +134,7 @@ describe('recognize', () => {
|
|||
{ path: 'a', component: ComponentA },
|
||||
{ path: 'c', component: ComponentC, outlet: 'c' },
|
||||
{ path: 'b', component: ComponentB, outlet: 'b' }
|
||||
], "a(c:c//b:b)", s => {
|
||||
], "a(c:c//b:b)", (s:RouterStateSnapshot) => {
|
||||
const c = s.children(s.root);
|
||||
checkActivatedRoute(c[0], "a", {}, ComponentA);
|
||||
checkActivatedRoute(c[1], "b", {}, ComponentB, 'b');
|
||||
|
@ -150,7 +150,7 @@ describe('recognize', () => {
|
|||
]
|
||||
},
|
||||
{ path: 'c', component: ComponentC, outlet: 'left' }
|
||||
], "a;a1=11;a2=22/b;b1=111;b2=222(left:c;c1=1111;c2=2222)", s => {
|
||||
], "a;a1=11;a2=22/b;b1=111;b2=222(left:c;c1=1111;c2=2222)", (s:RouterStateSnapshot) => {
|
||||
const c = s.children(s.root);
|
||||
checkActivatedRoute(c[0], "a", {a1: '11', a2: '22'}, ComponentA);
|
||||
checkActivatedRoute(s.firstChild(<any>c[0]), "b", {b1: '111', b2: '222'}, ComponentB);
|
||||
|
@ -162,7 +162,7 @@ describe('recognize', () => {
|
|||
it("should support root index routes", () => {
|
||||
checkRecognize([
|
||||
{index: true, component: ComponentA}
|
||||
], "", s => {
|
||||
], "", (s:RouterStateSnapshot) => {
|
||||
checkActivatedRoute(s.firstChild(s.root), "", {}, ComponentA);
|
||||
});
|
||||
});
|
||||
|
@ -170,7 +170,7 @@ describe('recognize', () => {
|
|||
it("should support nested root index routes", () => {
|
||||
checkRecognize([
|
||||
{index: true, component: ComponentA, children: [{index: true, component: ComponentB}]}
|
||||
], "", s => {
|
||||
], "", (s:RouterStateSnapshot) => {
|
||||
checkActivatedRoute(s.firstChild(s.root), "", {}, ComponentA);
|
||||
checkActivatedRoute(s.firstChild(<any>s.firstChild(s.root)), "", {}, ComponentB);
|
||||
});
|
||||
|
@ -181,7 +181,7 @@ describe('recognize', () => {
|
|||
{path: 'a', component: ComponentA, children: [
|
||||
{index: true, component: ComponentB}
|
||||
]}
|
||||
], "a", s => {
|
||||
], "a", (s:RouterStateSnapshot) => {
|
||||
checkActivatedRoute(s.firstChild(s.root), "a", {}, ComponentA);
|
||||
checkActivatedRoute(s.firstChild(<any>s.firstChild(s.root)), "", {}, ComponentB);
|
||||
});
|
||||
|
@ -197,7 +197,7 @@ describe('recognize', () => {
|
|||
}
|
||||
]
|
||||
}
|
||||
], "c/10", s => {
|
||||
], "c/10", (s:RouterStateSnapshot) => {
|
||||
checkActivatedRoute(s.firstChild(s.root), "", {}, ComponentA);
|
||||
checkActivatedRoute(s.firstChild(<any>s.firstChild(s.root)), "", {}, ComponentB);
|
||||
checkActivatedRoute(
|
||||
|
@ -208,7 +208,7 @@ describe('recognize', () => {
|
|||
xit("should pass parameters to every nested index route (case with non-index route)", () => {
|
||||
checkRecognize([
|
||||
{path: 'a', component: ComponentA, children: [{index: true, component: ComponentB}]}
|
||||
], "/a;a=1", s => {
|
||||
], "/a;a=1", (s:RouterStateSnapshot) => {
|
||||
checkActivatedRoute(s.firstChild(s.root), "a", {a: '1'}, ComponentA);
|
||||
checkActivatedRoute(s.firstChild(<any>s.firstChild(s.root)), "", {a: '1'}, ComponentB);
|
||||
});
|
||||
|
@ -219,7 +219,7 @@ describe('recognize', () => {
|
|||
it("should support root index routes", () => {
|
||||
recognize(RootComponent, [
|
||||
{path: '', component: ComponentA}
|
||||
], tree(""), "").forEach(s => {
|
||||
], tree(""), "").forEach((s:RouterStateSnapshot) => {
|
||||
checkActivatedRoute(s.firstChild(s.root), "", {}, ComponentA);
|
||||
});
|
||||
});
|
||||
|
@ -227,7 +227,7 @@ describe('recognize', () => {
|
|||
it("should support nested root index routes", () => {
|
||||
recognize(RootComponent, [
|
||||
{path: '', component: ComponentA, children: [{path: '', component: ComponentB}]}
|
||||
], tree(""), "").forEach(s => {
|
||||
], tree(""), "").forEach((s:RouterStateSnapshot) => {
|
||||
checkActivatedRoute(s.firstChild(s.root), "", {}, ComponentA);
|
||||
checkActivatedRoute(s.firstChild(<any>s.firstChild(s.root)), "", {}, ComponentB);
|
||||
});
|
||||
|
@ -237,7 +237,7 @@ describe('recognize', () => {
|
|||
const url = tree("");
|
||||
recognize(RootComponent, [
|
||||
{path: '', component: ComponentA, children: [{path: '', component: ComponentB}]}
|
||||
], url, "").forEach(s => {
|
||||
], url, "").forEach((s:RouterStateSnapshot) => {
|
||||
expect(s.root._urlSegment).toBe(url.root);
|
||||
expect(s.root._lastPathIndex).toBe(-1);
|
||||
|
||||
|
@ -256,7 +256,7 @@ describe('recognize', () => {
|
|||
{path: 'a', component: ComponentA, children: [
|
||||
{path: '', component: ComponentB}
|
||||
]}
|
||||
], tree("a"), "a").forEach(s => {
|
||||
], tree("a"), "a").forEach((s:RouterStateSnapshot) => {
|
||||
checkActivatedRoute(s.firstChild(s.root), "a", {}, ComponentA);
|
||||
checkActivatedRoute(s.firstChild(<any>s.firstChild(s.root)), "", {}, ComponentB);
|
||||
});
|
||||
|
@ -272,7 +272,7 @@ describe('recognize', () => {
|
|||
}
|
||||
]
|
||||
}
|
||||
], tree("c/10"), "c/10").forEach(s => {
|
||||
], tree("c/10"), "c/10").forEach((s:RouterStateSnapshot) => {
|
||||
checkActivatedRoute(s.firstChild(s.root), "", {}, ComponentA);
|
||||
checkActivatedRoute(s.firstChild(<any>s.firstChild(s.root)), "", {}, ComponentB);
|
||||
checkActivatedRoute(
|
||||
|
@ -283,7 +283,7 @@ describe('recognize', () => {
|
|||
xit("should pass parameters to every nested index route (case with non-index route)", () => {
|
||||
recognize(RootComponent, [
|
||||
{path: 'a', component: ComponentA, children: [{path: '', component: ComponentB}]}
|
||||
], tree("/a;a=1"), "/a;a=1").forEach(s => {
|
||||
], tree("/a;a=1"), "/a;a=1").forEach((s:RouterStateSnapshot) => {
|
||||
checkActivatedRoute(s.firstChild(s.root), "a", {a: '1'}, ComponentA);
|
||||
checkActivatedRoute(s.firstChild(<any>s.firstChild(s.root)), "", {a: '1'}, ComponentB);
|
||||
});
|
||||
|
@ -294,7 +294,7 @@ describe('recognize', () => {
|
|||
it("should support simple wildcards", () => {
|
||||
checkRecognize([
|
||||
{path: '**', component: ComponentA}
|
||||
], "a/b/c/d;a1=11", s => {
|
||||
], "a/b/c/d;a1=11", (s:RouterStateSnapshot) => {
|
||||
checkActivatedRoute(s.firstChild(s.root), "a/b/c/d", {a1:'11'}, ComponentA);
|
||||
});
|
||||
});
|
||||
|
@ -303,7 +303,7 @@ describe('recognize', () => {
|
|||
describe("query parameters", () => {
|
||||
it("should support query params", () => {
|
||||
const config = [{path: 'a', component: ComponentA}];
|
||||
checkRecognize(config, "a?q=11", s => {
|
||||
checkRecognize(config, "a?q=11", (s:RouterStateSnapshot) => {
|
||||
expect(s.queryParams).toEqual({q: '11'});
|
||||
});
|
||||
});
|
||||
|
@ -312,7 +312,7 @@ describe('recognize', () => {
|
|||
describe("fragment", () => {
|
||||
it("should support fragment", () => {
|
||||
const config = [{path: 'a', component: ComponentA}];
|
||||
checkRecognize(config, "a#f1", s => {
|
||||
checkRecognize(config, "a#f1", (s:RouterStateSnapshot) => {
|
||||
expect(s.fragment).toEqual("f1");
|
||||
});
|
||||
});
|
||||
|
@ -324,7 +324,7 @@ describe('recognize', () => {
|
|||
{ path: 'a', component: ComponentA },
|
||||
{ path: 'b', component: ComponentB, outlet: 'aux' },
|
||||
{ path: 'c', component: ComponentC, outlet: 'aux' }
|
||||
], tree("a(aux:b//aux:c)"), "a(aux:b//aux:c)").subscribe((_) => {}, s => {
|
||||
], tree("a(aux:b//aux:c)"), "a(aux:b//aux:c)").subscribe((_) => {}, (s:RouterStateSnapshot) => {
|
||||
expect(s.toString()).toContain("Two segments cannot have the same outlet name: 'aux:b' and 'aux:c'.");
|
||||
});
|
||||
});
|
||||
|
@ -332,7 +332,7 @@ describe('recognize', () => {
|
|||
it("should error when no matching routes", () => {
|
||||
recognize(RootComponent, [
|
||||
{ path: 'a', component: ComponentA }
|
||||
], tree("invalid"), "invalid").subscribe((_) => {}, s => {
|
||||
], tree("invalid"), "invalid").subscribe((_) => {}, (s:RouterStateSnapshot) => {
|
||||
expect(s.toString()).toContain("Cannot match any routes");
|
||||
});
|
||||
});
|
||||
|
@ -340,7 +340,7 @@ describe('recognize', () => {
|
|||
it("should error when no matching routes (too short)", () => {
|
||||
recognize(RootComponent, [
|
||||
{ path: 'a/:id', component: ComponentA }
|
||||
], tree("a"), "a").subscribe((_) => {}, s => {
|
||||
], tree("a"), "a").subscribe((_) => {}, (s:RouterStateSnapshot) => {
|
||||
expect(s.toString()).toContain("Cannot match any routes");
|
||||
});
|
||||
});
|
||||
|
|
|
@ -16,6 +16,7 @@ import {
|
|||
|
||||
import {TestComponentBuilder, ComponentFixture} from '@angular/compiler/testing';
|
||||
import { ComponentResolver } from '@angular/core';
|
||||
import { Location } from '@angular/common';
|
||||
import { SpyLocation } from '@angular/common/testing';
|
||||
import { UrlSerializer, DefaultUrlSerializer, RouterOutletMap, Router, ActivatedRoute, ROUTER_DIRECTIVES, Params,
|
||||
RouterStateSnapshot, ActivatedRouteSnapshot, CanActivate, CanDeactivate, Event, NavigationStart, NavigationEnd, NavigationCancel, NavigationError, RoutesRecognized, RouterConfig } from '../src/index';
|
||||
|
@ -37,19 +38,19 @@ describe("Integration", () => {
|
|||
{provide: Location, useClass: SpyLocation},
|
||||
{
|
||||
provide: Router,
|
||||
useFactory: (resolver, urlSerializer, outletMap, location, injector) => {
|
||||
useFactory: (resolver:ComponentResolver, urlSerializer:UrlSerializer, outletMap:RouterOutletMap, location:Location, injector:Injector) => {
|
||||
const r = new Router(RootCmp, resolver, urlSerializer, outletMap, location, injector, config);
|
||||
r.initialNavigation();
|
||||
return r;
|
||||
},
|
||||
deps: [ComponentResolver, UrlSerializer, RouterOutletMap, Location, Injector]
|
||||
},
|
||||
{provide: ActivatedRoute, useFactory: (r) => r.routerState.root, deps: [Router]},
|
||||
{provide: ActivatedRoute, useFactory: (r:Router) => r.routerState.root, deps: [Router]},
|
||||
];
|
||||
});
|
||||
|
||||
it('should navigate with a provided config',
|
||||
fakeAsync(inject([Router, TestComponentBuilder, Location], (router, tcb, location) => {
|
||||
fakeAsync(inject([Router, TestComponentBuilder, Location], (router:Router, tcb:TestComponentBuilder, location:Location) => {
|
||||
const fixture = tcb.createFakeAsync(RootCmp);
|
||||
advance(fixture);
|
||||
|
||||
|
@ -61,7 +62,7 @@ describe("Integration", () => {
|
|||
|
||||
|
||||
it('should update location when navigating',
|
||||
fakeAsync(inject([Router, TestComponentBuilder, Location], (router, tcb, location) => {
|
||||
fakeAsync(inject([Router, TestComponentBuilder, Location], (router:Router, tcb:TestComponentBuilder, location:Location) => {
|
||||
const fixture = tcb.createFakeAsync(RootCmp);
|
||||
advance(fixture);
|
||||
|
||||
|
@ -80,7 +81,7 @@ describe("Integration", () => {
|
|||
})));
|
||||
|
||||
it('should navigate back and forward',
|
||||
fakeAsync(inject([Router, TestComponentBuilder, Location], (router, tcb, location) => {
|
||||
fakeAsync(inject([Router, TestComponentBuilder, Location], (router:Router, tcb:TestComponentBuilder, location:Location) => {
|
||||
const fixture = tcb.createFakeAsync(RootCmp);
|
||||
advance(fixture);
|
||||
|
||||
|
@ -109,7 +110,7 @@ describe("Integration", () => {
|
|||
})));
|
||||
|
||||
it('should navigate when locations changes',
|
||||
fakeAsync(inject([Router, TestComponentBuilder, Location], (router, tcb, location) => {
|
||||
fakeAsync(inject([Router, TestComponentBuilder, Location], (router:Router, tcb:TestComponentBuilder, location:Location) => {
|
||||
const fixture = tcb.createFakeAsync(RootCmp);
|
||||
advance(fixture);
|
||||
|
||||
|
@ -122,14 +123,14 @@ describe("Integration", () => {
|
|||
router.navigateByUrl('/team/22/user/victor');
|
||||
advance(fixture);
|
||||
|
||||
location.simulateHashChange("/team/22/user/fedor");
|
||||
(<any>location).simulateHashChange("/team/22/user/fedor");
|
||||
advance(fixture);
|
||||
|
||||
expect(fixture.debugElement.nativeElement).toHaveText('team 22 { user fedor, right: }');
|
||||
})));
|
||||
|
||||
it('should update the location when the matched route does not change',
|
||||
fakeAsync(inject([Router, TestComponentBuilder, Location], (router, tcb, location) => {
|
||||
fakeAsync(inject([Router, TestComponentBuilder, Location], (router:Router, tcb:TestComponentBuilder, location:Location) => {
|
||||
const fixture = tcb.createFakeAsync(RootCmp);
|
||||
advance(fixture);
|
||||
|
||||
|
@ -149,7 +150,7 @@ describe("Integration", () => {
|
|||
})));
|
||||
|
||||
it('should support secondary routes',
|
||||
fakeAsync(inject([Router, TestComponentBuilder], (router, tcb) => {
|
||||
fakeAsync(inject([Router, TestComponentBuilder], (router:Router, tcb:TestComponentBuilder) => {
|
||||
const fixture = tcb.createFakeAsync(RootCmp);
|
||||
advance(fixture);
|
||||
|
||||
|
@ -168,7 +169,7 @@ describe("Integration", () => {
|
|||
})));
|
||||
|
||||
it('should deactivate outlets',
|
||||
fakeAsync(inject([Router, TestComponentBuilder], (router, tcb) => {
|
||||
fakeAsync(inject([Router, TestComponentBuilder], (router:Router, tcb:TestComponentBuilder) => {
|
||||
const fixture = tcb.createFakeAsync(RootCmp);
|
||||
advance(fixture);
|
||||
|
||||
|
@ -189,7 +190,7 @@ describe("Integration", () => {
|
|||
})));
|
||||
|
||||
it('should deactivate nested outlets',
|
||||
fakeAsync(inject([Router, TestComponentBuilder], (router, tcb) => {
|
||||
fakeAsync(inject([Router, TestComponentBuilder], (router:Router, tcb:TestComponentBuilder) => {
|
||||
const fixture = tcb.createFakeAsync(RootCmp);
|
||||
advance(fixture);
|
||||
|
||||
|
@ -211,7 +212,7 @@ describe("Integration", () => {
|
|||
})));
|
||||
|
||||
it('should set query params and fragment',
|
||||
fakeAsync(inject([Router, TestComponentBuilder], (router, tcb) => {
|
||||
fakeAsync(inject([Router, TestComponentBuilder], (router:Router, tcb:TestComponentBuilder) => {
|
||||
const fixture = tcb.createFakeAsync(RootCmp);
|
||||
advance(fixture);
|
||||
|
||||
|
@ -229,7 +230,7 @@ describe("Integration", () => {
|
|||
})));
|
||||
|
||||
it('should push params only when they change',
|
||||
fakeAsync(inject([Router, TestComponentBuilder], (router, tcb:TestComponentBuilder) => {
|
||||
fakeAsync(inject([Router, TestComponentBuilder], (router:Router, tcb:TestComponentBuilder) => {
|
||||
const fixture = tcb.createFakeAsync(RootCmp);
|
||||
advance(fixture);
|
||||
|
||||
|
@ -255,7 +256,7 @@ describe("Integration", () => {
|
|||
})));
|
||||
|
||||
it('should work when navigating to /',
|
||||
fakeAsync(inject([Router, TestComponentBuilder], (router, tcb:TestComponentBuilder) => {
|
||||
fakeAsync(inject([Router, TestComponentBuilder], (router:Router, tcb:TestComponentBuilder) => {
|
||||
const fixture = tcb.createFakeAsync(RootCmp);
|
||||
advance(fixture);
|
||||
|
||||
|
@ -276,7 +277,7 @@ describe("Integration", () => {
|
|||
})));
|
||||
|
||||
it("should cancel in-flight navigations",
|
||||
fakeAsync(inject([Router, TestComponentBuilder], (router, tcb:TestComponentBuilder) => {
|
||||
fakeAsync(inject([Router, TestComponentBuilder], (router:Router, tcb:TestComponentBuilder) => {
|
||||
const fixture = tcb.createFakeAsync(RootCmp);
|
||||
advance(fixture);
|
||||
|
||||
|
@ -284,7 +285,7 @@ describe("Integration", () => {
|
|||
{ path: '/user/:name', component: UserCmp }
|
||||
]);
|
||||
|
||||
const recordedEvents = [];
|
||||
const recordedEvents:any = [];
|
||||
router.events.forEach(e => recordedEvents.push(e));
|
||||
|
||||
router.navigateByUrl('/user/init');
|
||||
|
@ -292,7 +293,7 @@ describe("Integration", () => {
|
|||
|
||||
const user = fixture.debugElement.children[1].componentInstance;
|
||||
|
||||
let r1, r2;
|
||||
let r1:any, r2:any;
|
||||
router.navigateByUrl('/user/victor').then(_ => r1 = _);
|
||||
router.navigateByUrl('/user/fedor').then(_ => r2 = _);
|
||||
advance(fixture);
|
||||
|
@ -318,7 +319,7 @@ describe("Integration", () => {
|
|||
})));
|
||||
|
||||
it("should handle failed navigations gracefully",
|
||||
fakeAsync(inject([Router, TestComponentBuilder], (router, tcb:TestComponentBuilder) => {
|
||||
fakeAsync(inject([Router, TestComponentBuilder], (router:Router, tcb:TestComponentBuilder) => {
|
||||
const fixture = tcb.createFakeAsync(RootCmp);
|
||||
advance(fixture);
|
||||
|
||||
|
@ -326,10 +327,10 @@ describe("Integration", () => {
|
|||
{ path: '/user/:name', component: UserCmp }
|
||||
]);
|
||||
|
||||
const recordedEvents = [];
|
||||
const recordedEvents:any = [];
|
||||
router.events.forEach(e => recordedEvents.push(e));
|
||||
|
||||
let e;
|
||||
let e:any;
|
||||
router.navigateByUrl('/invalid').catch(_ => e = _);
|
||||
advance(fixture);
|
||||
expect(e.message).toContain("Cannot match any routes");
|
||||
|
@ -350,7 +351,7 @@ describe("Integration", () => {
|
|||
})));
|
||||
|
||||
it('should replace state when path is equal to current path',
|
||||
fakeAsync(inject([Router, TestComponentBuilder, Location], (router, tcb, location) => {
|
||||
fakeAsync(inject([Router, TestComponentBuilder, Location], (router:Router, tcb:TestComponentBuilder, location:Location) => {
|
||||
const fixture = tcb.createFakeAsync(RootCmp);
|
||||
advance(fixture);
|
||||
|
||||
|
@ -377,7 +378,7 @@ describe("Integration", () => {
|
|||
|
||||
describe("router links", () => {
|
||||
it("should support string router links",
|
||||
fakeAsync(inject([Router, TestComponentBuilder], (router, tcb) => {
|
||||
fakeAsync(inject([Router, TestComponentBuilder], (router:Router, tcb:TestComponentBuilder) => {
|
||||
const fixture = tcb.createFakeAsync(RootCmp);
|
||||
advance(fixture);
|
||||
|
||||
|
@ -401,7 +402,7 @@ describe("Integration", () => {
|
|||
})));
|
||||
|
||||
it("should support absolute router links",
|
||||
fakeAsync(inject([Router, TestComponentBuilder], (router, tcb) => {
|
||||
fakeAsync(inject([Router, TestComponentBuilder], (router:Router, tcb:TestComponentBuilder) => {
|
||||
const fixture = tcb.createFakeAsync(RootCmp);
|
||||
advance(fixture);
|
||||
|
||||
|
@ -425,7 +426,7 @@ describe("Integration", () => {
|
|||
})));
|
||||
|
||||
it("should support relative router links",
|
||||
fakeAsync(inject([Router, TestComponentBuilder], (router, tcb) => {
|
||||
fakeAsync(inject([Router, TestComponentBuilder], (router:Router, tcb:TestComponentBuilder) => {
|
||||
const fixture = tcb.createFakeAsync(RootCmp);
|
||||
advance(fixture);
|
||||
|
||||
|
@ -451,7 +452,7 @@ describe("Integration", () => {
|
|||
})));
|
||||
|
||||
it("should support top-level link",
|
||||
fakeAsync(inject([Router, TestComponentBuilder], (router, tcb) => {
|
||||
fakeAsync(inject([Router, TestComponentBuilder], (router:Router, tcb:TestComponentBuilder) => {
|
||||
let fixture = tcb.createFakeAsync(AbsoluteLinkCmp);
|
||||
advance(fixture);
|
||||
|
||||
|
@ -459,7 +460,7 @@ describe("Integration", () => {
|
|||
})));
|
||||
|
||||
it("should support query params and fragments",
|
||||
fakeAsync(inject([Router, Location, TestComponentBuilder], (router, location, tcb) => {
|
||||
fakeAsync(inject([Router, Location, TestComponentBuilder], (router:Router, location:Location, tcb:TestComponentBuilder) => {
|
||||
const fixture = tcb.createFakeAsync(RootCmp);
|
||||
advance(fixture);
|
||||
|
||||
|
@ -486,7 +487,7 @@ describe("Integration", () => {
|
|||
});
|
||||
|
||||
describe("redirects", () => {
|
||||
it("should work", fakeAsync(inject([Router, TestComponentBuilder, Location], (router, tcb, location) => {
|
||||
it("should work", fakeAsync(inject([Router, TestComponentBuilder, Location], (router:Router, tcb:TestComponentBuilder, location:Location) => {
|
||||
const fixture = tcb.createFakeAsync(RootCmp);
|
||||
advance(fixture);
|
||||
|
||||
|
@ -506,11 +507,11 @@ describe("Integration", () => {
|
|||
describe("CanActivate", () => {
|
||||
describe("should not activate a route when CanActivate returns false", () => {
|
||||
beforeEachProviders(() => [
|
||||
{provide: 'alwaysFalse', useValue: (a, b) => false}
|
||||
{provide: 'alwaysFalse', useValue: (a:any, b:any) => false}
|
||||
]);
|
||||
|
||||
it('works',
|
||||
fakeAsync(inject([Router, TestComponentBuilder, Location], (router, tcb, location) => {
|
||||
fakeAsync(inject([Router, TestComponentBuilder, Location], (router:Router, tcb:TestComponentBuilder, location:Location) => {
|
||||
const fixture = tcb.createFakeAsync(RootCmp);
|
||||
advance(fixture);
|
||||
|
||||
|
@ -531,7 +532,7 @@ describe("Integration", () => {
|
|||
]);
|
||||
|
||||
it('works',
|
||||
fakeAsync(inject([Router, TestComponentBuilder, Location], (router, tcb, location) => {
|
||||
fakeAsync(inject([Router, TestComponentBuilder, Location], (router:Router, tcb:TestComponentBuilder, location:Location) => {
|
||||
const fixture = tcb.createFakeAsync(RootCmp);
|
||||
advance(fixture);
|
||||
|
||||
|
@ -556,7 +557,7 @@ describe("Integration", () => {
|
|||
beforeEachProviders(() => [AlwaysTrue]);
|
||||
|
||||
it('works',
|
||||
fakeAsync(inject([Router, TestComponentBuilder, Location], (router, tcb, location) => {
|
||||
fakeAsync(inject([Router, TestComponentBuilder, Location], (router:Router, tcb:TestComponentBuilder, location:Location) => {
|
||||
const fixture = tcb.createFakeAsync(RootCmp);
|
||||
advance(fixture);
|
||||
|
||||
|
@ -579,7 +580,7 @@ describe("Integration", () => {
|
|||
]);
|
||||
|
||||
it('works',
|
||||
fakeAsync(inject([Router, TestComponentBuilder, Location], (router, tcb, location) => {
|
||||
fakeAsync(inject([Router, TestComponentBuilder, Location], (router:Router, tcb:TestComponentBuilder, location:Location) => {
|
||||
const fixture = tcb.createFakeAsync(RootCmp);
|
||||
advance(fixture);
|
||||
|
||||
|
@ -607,7 +608,7 @@ describe("Integration", () => {
|
|||
|
||||
|
||||
it('works',
|
||||
fakeAsync(inject([Router, TestComponentBuilder, Location], (router, tcb, location) => {
|
||||
fakeAsync(inject([Router, TestComponentBuilder, Location], (router:Router, tcb:TestComponentBuilder, location:Location) => {
|
||||
const fixture = tcb.createFakeAsync(RootCmp);
|
||||
advance(fixture);
|
||||
|
||||
|
@ -632,7 +633,7 @@ describe("Integration", () => {
|
|||
})));
|
||||
|
||||
it('works with a nested route',
|
||||
fakeAsync(inject([Router, TestComponentBuilder, Location], (router, tcb, location) => {
|
||||
fakeAsync(inject([Router, TestComponentBuilder, Location], (router:Router, tcb:TestComponentBuilder, location:Location) => {
|
||||
const fixture = tcb.createFakeAsync(RootCmp);
|
||||
advance(fixture);
|
||||
|
||||
|
@ -671,7 +672,7 @@ describe("Integration", () => {
|
|||
beforeEachProviders(() => [AlwaysTrue]);
|
||||
|
||||
it('works',
|
||||
fakeAsync(inject([Router, TestComponentBuilder, Location], (router, tcb, location) => {
|
||||
fakeAsync(inject([Router, TestComponentBuilder, Location], (router:Router, tcb:TestComponentBuilder, location:Location) => {
|
||||
const fixture = tcb.createFakeAsync(RootCmp);
|
||||
advance(fixture);
|
||||
|
||||
|
@ -698,7 +699,7 @@ describe("Integration", () => {
|
|||
]);
|
||||
|
||||
it('works',
|
||||
fakeAsync(inject([Router, TestComponentBuilder, Location], (router, tcb, location) => {
|
||||
fakeAsync(inject([Router, TestComponentBuilder, Location], (router:Router, tcb:TestComponentBuilder, location:Location) => {
|
||||
const fixture = tcb.createFakeAsync(RootCmp);
|
||||
advance(fixture);
|
||||
|
||||
|
@ -719,7 +720,7 @@ describe("Integration", () => {
|
|||
|
||||
describe("routerActiveLink", () => {
|
||||
it("should set the class when the link is active (exact = true)",
|
||||
fakeAsync(inject([Router, TestComponentBuilder, Location], (router, tcb, location) => {
|
||||
fakeAsync(inject([Router, TestComponentBuilder, Location], (router:Router, tcb:TestComponentBuilder, location:Location) => {
|
||||
const fixture = tcb.createFakeAsync(RootCmp);
|
||||
advance(fixture);
|
||||
|
||||
|
@ -746,7 +747,7 @@ describe("Integration", () => {
|
|||
})));
|
||||
|
||||
it("should set the class on a parent element when the link is active (exact = true)",
|
||||
fakeAsync(inject([Router, TestComponentBuilder, Location], (router, tcb, location) => {
|
||||
fakeAsync(inject([Router, TestComponentBuilder, Location], (router:Router, tcb:TestComponentBuilder, location:Location) => {
|
||||
const fixture = tcb.createFakeAsync(RootCmp);
|
||||
advance(fixture);
|
||||
|
||||
|
@ -773,7 +774,7 @@ describe("Integration", () => {
|
|||
})));
|
||||
|
||||
it("should set the class when the link is active (exact = false)",
|
||||
fakeAsync(inject([Router, TestComponentBuilder, Location], (router, tcb, location) => {
|
||||
fakeAsync(inject([Router, TestComponentBuilder, Location], (router:Router, tcb:TestComponentBuilder, location:Location) => {
|
||||
const fixture = tcb.createFakeAsync(RootCmp);
|
||||
advance(fixture);
|
||||
|
||||
|
|
|
@ -5,7 +5,8 @@
|
|||
"noEmitOnError": false,
|
||||
"module": "commonjs",
|
||||
"target": "es5",
|
||||
"noImplicitAny": false,
|
||||
"noImplicitAny": true,
|
||||
"noImplicitReturns": true,
|
||||
"outDir": "dist",
|
||||
"rootDir": ".",
|
||||
"inlineSourceMap": true,
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
"emitDecoratorMetadata": true,
|
||||
"module": "commonjs",
|
||||
"target": "es5",
|
||||
"noImplicitAny": false,
|
||||
"noImplicitAny": true,
|
||||
"noImplicitReturns": true,
|
||||
"outDir": "dist",
|
||||
"rootDir": "src",
|
||||
"inlineSourceMap": true,
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
"experimentalDecorators": true,
|
||||
"emitDecoratorMetadata": true,
|
||||
"target": "es6",
|
||||
"noImplicitAny": false,
|
||||
"noImplicitAny": true,
|
||||
"noImplicitReturns": true,
|
||||
"outDir": "dist/esm",
|
||||
"rootDir": "src",
|
||||
"inlineSourceMap": true,
|
||||
|
|
Loading…
Reference in New Issue