@angular/router-deprecated
Version:
1,272 lines • 155 kB
JavaScript
/**
* @license AngularJS v0.0.0-PLACEHOLDER
* (c) 2010-2016 Google, Inc. https://angular.io/
* License: MIT
*/
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/common'), require('@angular/core'), require('rxjs/Subject'), require('rxjs/observable/PromiseObservable'), require('rxjs/operator/toPromise'), require('rxjs/Observable'), require('@angular/platform-browser')) :
typeof define === 'function' && define.amd ? define(['exports', '@angular/common', '@angular/core', 'rxjs/Subject', 'rxjs/observable/PromiseObservable', 'rxjs/operator/toPromise', 'rxjs/Observable', '@angular/platform-browser'], factory) :
(factory((global.ng = global.ng || {}, global.ng.router_deprecated = global.ng.router_deprecated || {}), global.ng.common, global.ng.core, global.Rx, global.Rx, global.Rx.Observable.prototype, global.Rx, global.ng.platformBrowser));
}(this, function (exports, _angular_common, _angular_core, rxjs_Subject, rxjs_observable_PromiseObservable, rxjs_operator_toPromise, rxjs_Observable, _angular_platformBrowser) {
'use strict';
var globalScope;
if (typeof window === 'undefined') {
if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) {
// TODO: Replace any with WorkerGlobalScope from lib.webworker.d.ts #3492
globalScope = self;
}
else {
globalScope = global;
}
}
else {
globalScope = window;
}
// Need to declare a new variable for global here since TypeScript
// exports the original value of the symbol.
var global$1 = globalScope;
var Type$1 = Function;
function getTypeNameForDebugging(type) {
if (type['name']) {
return type['name'];
}
return typeof type;
}
var Math = global$1.Math;
// TODO: remove calls to assert in production environment
// Note: Can't just export this and import in in other files
// as `assert` is a reserved keyword in Dart
global$1.assert = function assert(condition) {
// TODO: to be fixed properly via #2830, noop for now
};
function isPresent(obj) {
return obj !== undefined && obj !== null;
}
function isBlank(obj) {
return obj === undefined || obj === null;
}
function isString(obj) {
return typeof obj === 'string';
}
function isFunction(obj) {
return typeof obj === 'function';
}
function isType(obj) {
return isFunction(obj);
}
function isStringMap(obj) {
return typeof obj === 'object' && obj !== null;
}
function isArray(obj) {
return Array.isArray(obj);
}
function noop() { }
var StringWrapper = (function () {
function StringWrapper() {
}
StringWrapper.fromCharCode = function (code) { return String.fromCharCode(code); };
StringWrapper.charCodeAt = function (s, index) { return s.charCodeAt(index); };
StringWrapper.split = function (s, regExp) { return s.split(regExp); };
StringWrapper.equals = function (s, s2) { return s === s2; };
StringWrapper.stripLeft = function (s, charVal) {
if (s && s.length) {
var pos = 0;
for (var i = 0; i < s.length; i++) {
if (s[i] != charVal)
break;
pos++;
}
s = s.substring(pos);
}
return s;
};
StringWrapper.stripRight = function (s, charVal) {
if (s && s.length) {
var pos = s.length;
for (var i = s.length - 1; i >= 0; i--) {
if (s[i] != charVal)
break;
pos--;
}
s = s.substring(0, pos);
}
return s;
};
StringWrapper.replace = function (s, from, replace) {
return s.replace(from, replace);
};
StringWrapper.replaceAll = function (s, from, replace) {
return s.replace(from, replace);
};
StringWrapper.slice = function (s, from, to) {
if (from === void 0) { from = 0; }
if (to === void 0) { to = null; }
return s.slice(from, to === null ? undefined : to);
};
StringWrapper.replaceAllMapped = function (s, from, cb) {
return s.replace(from, function () {
var matches = [];
for (var _i = 0; _i < arguments.length; _i++) {
matches[_i - 0] = arguments[_i];
}
// Remove offset & string from the result array
matches.splice(-2, 2);
// The callback receives match, p1, ..., pn
return cb(matches);
});
};
StringWrapper.contains = function (s, substr) { return s.indexOf(substr) != -1; };
StringWrapper.compare = function (a, b) {
if (a < b) {
return -1;
}
else if (a > b) {
return 1;
}
else {
return 0;
}
};
return StringWrapper;
}());
var RegExpWrapper = (function () {
function RegExpWrapper() {
}
RegExpWrapper.create = function (regExpStr, flags) {
if (flags === void 0) { flags = ''; }
flags = flags.replace(/g/g, '');
return new global$1.RegExp(regExpStr, flags + 'g');
};
RegExpWrapper.firstMatch = function (regExp, input) {
// Reset multimatch regex state
regExp.lastIndex = 0;
return regExp.exec(input);
};
RegExpWrapper.test = function (regExp, input) {
regExp.lastIndex = 0;
return regExp.test(input);
};
RegExpWrapper.matcher = function (regExp, input) {
// Reset regex state for the case
// someone did not loop over all matches
// last time.
regExp.lastIndex = 0;
return { re: regExp, input: input };
};
RegExpWrapper.replaceAll = function (regExp, input, replace) {
var c = regExp.exec(input);
var res = '';
regExp.lastIndex = 0;
var prev = 0;
while (c) {
res += input.substring(prev, c.index);
res += replace(c);
prev = c.index + c[0].length;
regExp.lastIndex = prev;
c = regExp.exec(input);
}
res += input.substring(prev);
return res;
};
return RegExpWrapper;
}());
var RegExpMatcherWrapper = (function () {
function RegExpMatcherWrapper() {
}
RegExpMatcherWrapper.next = function (matcher) {
return matcher.re.exec(matcher.input);
};
return RegExpMatcherWrapper;
}());
function normalizeBlank(obj) {
return isBlank(obj) ? null : obj;
}
var PromiseCompleter = (function () {
function PromiseCompleter() {
var _this = this;
this.promise = new Promise(function (res, rej) {
_this.resolve = res;
_this.reject = rej;
});
}
return PromiseCompleter;
}());
var PromiseWrapper = (function () {
function PromiseWrapper() {
}
PromiseWrapper.resolve = function (obj) { return Promise.resolve(obj); };
PromiseWrapper.reject = function (obj, _) { return Promise.reject(obj); };
// Note: We can't rename this method into `catch`, as this is not a valid
// method name in Dart.
PromiseWrapper.catchError = function (promise, onError) {
return promise.catch(onError);
};
PromiseWrapper.all = function (promises) {
if (promises.length == 0)
return Promise.resolve([]);
return Promise.all(promises);
};
PromiseWrapper.then = function (promise, success, rejection) {
return promise.then(success, rejection);
};
PromiseWrapper.wrap = function (computation) {
return new Promise(function (res, rej) {
try {
res(computation());
}
catch (e) {
rej(e);
}
});
};
PromiseWrapper.scheduleMicrotask = function (computation) {
PromiseWrapper.then(PromiseWrapper.resolve(null), computation, function (_) { });
};
PromiseWrapper.isPromise = function (obj) { return obj instanceof Promise; };
PromiseWrapper.completer = function () { return new PromiseCompleter(); };
return PromiseWrapper;
}());
var ObservableWrapper = (function () {
function ObservableWrapper() {
}
// TODO(vsavkin): when we use rxnext, try inferring the generic type from the first arg
ObservableWrapper.subscribe = function (emitter, onNext, onError, onComplete) {
if (onComplete === void 0) { onComplete = function () { }; }
onError = (typeof onError === 'function') && onError || noop;
onComplete = (typeof onComplete === 'function') && onComplete || noop;
return emitter.subscribe({ next: onNext, error: onError, complete: onComplete });
};
ObservableWrapper.isObservable = function (obs) { return !!obs.subscribe; };
/**
* Returns whether `obs` has any subscribers listening to events.
*/
ObservableWrapper.hasSubscribers = function (obs) { return obs.observers.length > 0; };
ObservableWrapper.dispose = function (subscription) { subscription.unsubscribe(); };
/**
* @deprecated - use callEmit() instead
*/
ObservableWrapper.callNext = function (emitter, value) { emitter.next(value); };
ObservableWrapper.callEmit = function (emitter, value) { emitter.emit(value); };
ObservableWrapper.callError = function (emitter, error) { emitter.error(error); };
ObservableWrapper.callComplete = function (emitter) { emitter.complete(); };
ObservableWrapper.fromPromise = function (promise) {
return rxjs_observable_PromiseObservable.PromiseObservable.create(promise);
};
ObservableWrapper.toPromise = function (obj) { return rxjs_operator_toPromise.toPromise.call(obj); };
return ObservableWrapper;
}());
/**
* Use by directives and components to emit custom Events.
*
* ### Examples
*
* In the following example, `Zippy` alternatively emits `open` and `close` events when its
* title gets clicked:
*
* ```
* @Component({
* selector: 'zippy',
* template: `
* <div class="zippy">
* <div (click)="toggle()">Toggle</div>
* <div [hidden]="!visible">
* <ng-content></ng-content>
* </div>
* </div>`})
* export class Zippy {
* visible: boolean = true;
* @Output() open: EventEmitter<any> = new EventEmitter();
* @Output() close: EventEmitter<any> = new EventEmitter();
*
* toggle() {
* this.visible = !this.visible;
* if (this.visible) {
* this.open.emit(null);
* } else {
* this.close.emit(null);
* }
* }
* }
* ```
*
* The events payload can be accessed by the parameter `$event` on the components output event
* handler:
*
* ```
* <zippy (open)="onOpen($event)" (close)="onClose($event)"></zippy>
* ```
*
* Uses Rx.Observable but provides an adapter to make it work as specified here:
* https://github.com/jhusain/observable-spec
*
* Once a reference implementation of the spec is available, switch to it.
* @stable
*/
var EventEmitter = (function (_super) {
__extends(EventEmitter, _super);
/**
* Creates an instance of [EventEmitter], which depending on [isAsync],
* delivers events synchronously or asynchronously.
*/
function EventEmitter(isAsync) {
if (isAsync === void 0) { isAsync = false; }
_super.call(this);
this.__isAsync = isAsync;
}
EventEmitter.prototype.emit = function (value) { _super.prototype.next.call(this, value); };
/**
* @deprecated - use .emit(value) instead
*/
EventEmitter.prototype.next = function (value) { _super.prototype.next.call(this, value); };
EventEmitter.prototype.subscribe = function (generatorOrNext, error, complete) {
var schedulerFn;
var errorFn = function (err) { return null; };
var completeFn = function () { return null; };
if (generatorOrNext && typeof generatorOrNext === 'object') {
schedulerFn = this.__isAsync ? function (value /** TODO #9100 */) {
setTimeout(function () { return generatorOrNext.next(value); });
} : function (value /** TODO #9100 */) { generatorOrNext.next(value); };
if (generatorOrNext.error) {
errorFn = this.__isAsync ? function (err) { setTimeout(function () { return generatorOrNext.error(err); }); } :
function (err) { generatorOrNext.error(err); };
}
if (generatorOrNext.complete) {
completeFn = this.__isAsync ? function () { setTimeout(function () { return generatorOrNext.complete(); }); } :
function () { generatorOrNext.complete(); };
}
}
else {
schedulerFn = this.__isAsync ? function (value /** TODO #9100 */) {
setTimeout(function () { return generatorOrNext(value); });
} : function (value /** TODO #9100 */) { generatorOrNext(value); };
if (error) {
errorFn =
this.__isAsync ? function (err) { setTimeout(function () { return error(err); }); } : function (err) { error(err); };
}
if (complete) {
completeFn =
this.__isAsync ? function () { setTimeout(function () { return complete(); }); } : function () { complete(); };
}
}
return _super.prototype.subscribe.call(this, schedulerFn, errorFn, completeFn);
};
return EventEmitter;
}(rxjs_Subject.Subject));
var Map$1 = global$1.Map;
var Set = global$1.Set;
// Safari and Internet Explorer do not support the iterable parameter to the
// Map constructor. We work around that by manually adding the items.
var createMapFromPairs = (function () {
try {
if (new Map$1([[1, 2]]).size === 1) {
return function createMapFromPairs(pairs) { return new Map$1(pairs); };
}
}
catch (e) {
}
return function createMapAndPopulateFromPairs(pairs) {
var map = new Map$1();
for (var i = 0; i < pairs.length; i++) {
var pair = pairs[i];
map.set(pair[0], pair[1]);
}
return map;
};
})();
var createMapFromMap = (function () {
try {
if (new Map$1(new Map$1())) {
return function createMapFromMap(m) { return new Map$1(m); };
}
}
catch (e) {
}
return function createMapAndPopulateFromMap(m) {
var map = new Map$1();
m.forEach(function (v, k) { map.set(k, v); });
return map;
};
})();
var _clearValues = (function () {
if ((new Map$1()).keys().next) {
return function _clearValues(m) {
var keyIterator = m.keys();
var k;
while (!((k = keyIterator.next()).done)) {
m.set(k.value, null);
}
};
}
else {
return function _clearValuesWithForeEach(m) {
m.forEach(function (v, k) { m.set(k, null); });
};
}
})();
// Safari doesn't implement MapIterator.next(), which is used is Traceur's polyfill of Array.from
// TODO(mlaval): remove the work around once we have a working polyfill of Array.from
var _arrayFromMap = (function () {
try {
if ((new Map$1()).values().next) {
return function createArrayFromMap(m, getValues) {
return getValues ? Array.from(m.values()) : Array.from(m.keys());
};
}
}
catch (e) {
}
return function createArrayFromMapWithForeach(m, getValues) {
var res = ListWrapper.createFixedSize(m.size), i = 0;
m.forEach(function (v, k) {
res[i] = getValues ? v : k;
i++;
});
return res;
};
})();
/**
* Wraps Javascript Objects
*/
var StringMapWrapper = (function () {
function StringMapWrapper() {
}
StringMapWrapper.create = function () {
// Note: We are not using Object.create(null) here due to
// performance!
// http://jsperf.com/ng2-object-create-null
return {};
};
StringMapWrapper.contains = function (map, key) {
return map.hasOwnProperty(key);
};
StringMapWrapper.get = function (map, key) {
return map.hasOwnProperty(key) ? map[key] : undefined;
};
StringMapWrapper.set = function (map, key, value) { map[key] = value; };
StringMapWrapper.keys = function (map) { return Object.keys(map); };
StringMapWrapper.values = function (map) {
return Object.keys(map).reduce(function (r, a) {
r.push(map[a]);
return r;
}, []);
};
StringMapWrapper.isEmpty = function (map) {
for (var prop in map) {
return false;
}
return true;
};
StringMapWrapper.delete = function (map, key) { delete map[key]; };
StringMapWrapper.forEach = function (map, callback) {
for (var prop in map) {
if (map.hasOwnProperty(prop)) {
callback(map[prop], prop);
}
}
};
StringMapWrapper.merge = function (m1, m2) {
var m = {};
for (var attr in m1) {
if (m1.hasOwnProperty(attr)) {
m[attr] = m1[attr];
}
}
for (var attr in m2) {
if (m2.hasOwnProperty(attr)) {
m[attr] = m2[attr];
}
}
return m;
};
StringMapWrapper.equals = function (m1, m2) {
var k1 = Object.keys(m1);
var k2 = Object.keys(m2);
if (k1.length != k2.length) {
return false;
}
var key;
for (var i = 0; i < k1.length; i++) {
key = k1[i];
if (m1[key] !== m2[key]) {
return false;
}
}
return true;
};
return StringMapWrapper;
}());
var ListWrapper = (function () {
function ListWrapper() {
}
// JS has no way to express a statically fixed size list, but dart does so we
// keep both methods.
ListWrapper.createFixedSize = function (size) { return new Array(size); };
ListWrapper.createGrowableSize = function (size) { return new Array(size); };
ListWrapper.clone = function (array) { return array.slice(0); };
ListWrapper.forEachWithIndex = function (array, fn) {
for (var i = 0; i < array.length; i++) {
fn(array[i], i);
}
};
ListWrapper.first = function (array) {
if (!array)
return null;
return array[0];
};
ListWrapper.last = function (array) {
if (!array || array.length == 0)
return null;
return array[array.length - 1];
};
ListWrapper.indexOf = function (array, value, startIndex) {
if (startIndex === void 0) { startIndex = 0; }
return array.indexOf(value, startIndex);
};
ListWrapper.contains = function (list, el) { return list.indexOf(el) !== -1; };
ListWrapper.reversed = function (array) {
var a = ListWrapper.clone(array);
return a.reverse();
};
ListWrapper.concat = function (a, b) { return a.concat(b); };
ListWrapper.insert = function (list, index, value) { list.splice(index, 0, value); };
ListWrapper.removeAt = function (list, index) {
var res = list[index];
list.splice(index, 1);
return res;
};
ListWrapper.removeAll = function (list, items) {
for (var i = 0; i < items.length; ++i) {
var index = list.indexOf(items[i]);
list.splice(index, 1);
}
};
ListWrapper.remove = function (list, el) {
var index = list.indexOf(el);
if (index > -1) {
list.splice(index, 1);
return true;
}
return false;
};
ListWrapper.clear = function (list) { list.length = 0; };
ListWrapper.isEmpty = function (list) { return list.length == 0; };
ListWrapper.fill = function (list, value, start, end) {
if (start === void 0) { start = 0; }
if (end === void 0) { end = null; }
list.fill(value, start, end === null ? list.length : end);
};
ListWrapper.equals = function (a, b) {
if (a.length != b.length)
return false;
for (var i = 0; i < a.length; ++i) {
if (a[i] !== b[i])
return false;
}
return true;
};
ListWrapper.slice = function (l, from, to) {
if (from === void 0) { from = 0; }
if (to === void 0) { to = null; }
return l.slice(from, to === null ? undefined : to);
};
ListWrapper.splice = function (l, from, length) { return l.splice(from, length); };
ListWrapper.sort = function (l, compareFn) {
if (isPresent(compareFn)) {
l.sort(compareFn);
}
else {
l.sort();
}
};
ListWrapper.toString = function (l) { return l.toString(); };
ListWrapper.toJSON = function (l) { return JSON.stringify(l); };
ListWrapper.maximum = function (list, predicate) {
if (list.length == 0) {
return null;
}
var solution = null;
var maxValue = -Infinity;
for (var index = 0; index < list.length; index++) {
var candidate = list[index];
if (isBlank(candidate)) {
continue;
}
var candidateValue = predicate(candidate);
if (candidateValue > maxValue) {
solution = candidate;
maxValue = candidateValue;
}
}
return solution;
};
ListWrapper.flatten = function (list) {
var target = [];
_flattenArray(list, target);
return target;
};
ListWrapper.addAll = function (list, source) {
for (var i = 0; i < source.length; i++) {
list.push(source[i]);
}
};
return ListWrapper;
}());
function _flattenArray(source, target) {
if (isPresent(source)) {
for (var i = 0; i < source.length; i++) {
var item = source[i];
if (isArray(item)) {
_flattenArray(item, target);
}
else {
target.push(item);
}
}
}
return target;
}
// Safari and Internet Explorer do not support the iterable parameter to the
// Set constructor. We work around that by manually adding the items.
var createSetFromList = (function () {
var test = new Set([1, 2, 3]);
if (test.size === 3) {
return function createSetFromList(lst) { return new Set(lst); };
}
else {
return function createSetAndPopulateFromList(lst) {
var res = new Set(lst);
if (res.size !== lst.length) {
for (var i = 0; i < lst.length; i++) {
res.add(lst[i]);
}
}
return res;
};
}
})();
/**
* @stable
*/
var BaseException$1 = (function (_super) {
__extends(BaseException$1, _super);
function BaseException$1(message) {
if (message === void 0) { message = '--'; }
_super.call(this, message);
this.message = message;
this.stack = (new Error(message)).stack;
}
BaseException$1.prototype.toString = function () { return this.message; };
return BaseException$1;
}(Error));
/**
* `RouteParams` is an immutable map of parameters for the given route
* based on the url matcher and optional parameters for that route.
*
* You can inject `RouteParams` into the constructor of a component to use it.
*
* ### Example
*
* ```
* import {Component} from '@angular/core';
* import {bootstrap} from '@angular/platform-browser/browser';
* import {Router, ROUTER_DIRECTIVES, ROUTER_PROVIDERS, RouteConfig, RouteParams} from
* 'angular2/router';
*
* @Component({directives: [ROUTER_DIRECTIVES]})
* @RouteConfig([
* {path: '/user/:id', component: UserCmp, name: 'UserCmp'},
* ])
* class AppCmp {}
*
* @Component({ template: 'user: {{id}}' })
* class UserCmp {
* id: string;
* constructor(params: RouteParams) {
* this.id = params.get('id');
* }
* }
*
* bootstrap(AppCmp, ROUTER_PROVIDERS);
* ```
*/
var RouteParams = (function () {
function RouteParams(params) {
this.params = params;
}
RouteParams.prototype.get = function (param) { return normalizeBlank(StringMapWrapper.get(this.params, param)); };
return RouteParams;
}());
/**
* `RouteData` is an immutable map of additional data you can configure in your {@link Route}.
*
* You can inject `RouteData` into the constructor of a component to use it.
*
* ### Example
*
* ```
* import {Component} from '@angular/core';
* import {bootstrap} from '@angular/platform-browser/browser';
* import {Router, ROUTER_DIRECTIVES, ROUTER_PROVIDERS, RouteConfig, RouteData} from
* 'angular2/router';
*
* @Component({directives: [ROUTER_DIRECTIVES]})
* @RouteConfig([
* {path: '/user/:id', component: UserCmp, name: 'UserCmp', data: {isAdmin: true}},
* ])
* class AppCmp {}
*
* @Component({
* ...,
* template: 'user: {{isAdmin}}'
* })
* class UserCmp {
* string: isAdmin;
* constructor(data: RouteData) {
* this.isAdmin = data.get('isAdmin');
* }
* }
*
* bootstrap(AppCmp, ROUTER_PROVIDERS);
* ```
*/
var RouteData = (function () {
function RouteData(data) {
if (data === void 0) { data = {}; }
this.data = data;
}
RouteData.prototype.get = function (key) { return normalizeBlank(StringMapWrapper.get(this.data, key)); };
return RouteData;
}());
var BLANK_ROUTE_DATA = new RouteData();
/**
* `Instruction` is a tree of {@link ComponentInstruction}s with all the information needed
* to transition each component in the app to a given route, including all auxiliary routes.
*
* `Instruction`s can be created using {@link Router#generate}, and can be used to
* perform route changes with {@link Router#navigateByInstruction}.
*
* ### Example
*
* ```
* import {Component} from '@angular/core';
* import {bootstrap} from '@angular/platform-browser/browser';
* import {Router, ROUTER_DIRECTIVES, ROUTER_PROVIDERS, RouteConfig} from
* '@angular/router-deprecated';
*
* @Component({directives: [ROUTER_DIRECTIVES]})
* @RouteConfig([
* {...},
* ])
* class AppCmp {
* constructor(router: Router) {
* var instruction = router.generate(['/MyRoute']);
* router.navigateByInstruction(instruction);
* }
* }
*
* bootstrap(AppCmp, ROUTER_PROVIDERS);
* ```
*/
var Instruction = (function () {
function Instruction(component, child, auxInstruction) {
this.component = component;
this.child = child;
this.auxInstruction = auxInstruction;
}
Object.defineProperty(Instruction.prototype, "urlPath", {
get: function () { return isPresent(this.component) ? this.component.urlPath : ''; },
enumerable: true,
configurable: true
});
Object.defineProperty(Instruction.prototype, "urlParams", {
get: function () { return isPresent(this.component) ? this.component.urlParams : []; },
enumerable: true,
configurable: true
});
Object.defineProperty(Instruction.prototype, "specificity", {
get: function () {
var total = '';
if (isPresent(this.component)) {
total += this.component.specificity;
}
if (isPresent(this.child)) {
total += this.child.specificity;
}
return total;
},
enumerable: true,
configurable: true
});
/**
* converts the instruction into a URL string
*/
Instruction.prototype.toRootUrl = function () { return this.toUrlPath() + this.toUrlQuery(); };
/** @internal */
Instruction.prototype._toNonRootUrl = function () {
return this._stringifyPathMatrixAuxPrefixed() +
(isPresent(this.child) ? this.child._toNonRootUrl() : '');
};
Instruction.prototype.toUrlQuery = function () { return this.urlParams.length > 0 ? ('?' + this.urlParams.join('&')) : ''; };
/**
* Returns a new instruction that shares the state of the existing instruction, but with
* the given child {@link Instruction} replacing the existing child.
*/
Instruction.prototype.replaceChild = function (child) {
return new ResolvedInstruction(this.component, child, this.auxInstruction);
};
/**
* If the final URL for the instruction is ``
*/
Instruction.prototype.toUrlPath = function () {
return this.urlPath + this._stringifyAux() +
(isPresent(this.child) ? this.child._toNonRootUrl() : '');
};
// default instructions override these
Instruction.prototype.toLinkUrl = function () {
return this.urlPath + this._stringifyAux() +
(isPresent(this.child) ? this.child._toLinkUrl() : '') + this.toUrlQuery();
};
// this is the non-root version (called recursively)
/** @internal */
Instruction.prototype._toLinkUrl = function () {
return this._stringifyPathMatrixAuxPrefixed() +
(isPresent(this.child) ? this.child._toLinkUrl() : '');
};
/** @internal */
Instruction.prototype._stringifyPathMatrixAuxPrefixed = function () {
var primary = this._stringifyPathMatrixAux();
if (primary.length > 0) {
primary = '/' + primary;
}
return primary;
};
/** @internal */
Instruction.prototype._stringifyMatrixParams = function () {
return this.urlParams.length > 0 ? (';' + this.urlParams.join(';')) : '';
};
/** @internal */
Instruction.prototype._stringifyPathMatrixAux = function () {
if (isBlank(this.component) && isBlank(this.urlPath)) {
return '';
}
return this.urlPath + this._stringifyMatrixParams() + this._stringifyAux();
};
/** @internal */
Instruction.prototype._stringifyAux = function () {
var routes = [];
StringMapWrapper.forEach(this.auxInstruction, function (auxInstruction, _) {
routes.push(auxInstruction._stringifyPathMatrixAux());
});
if (routes.length > 0) {
return '(' + routes.join('//') + ')';
}
return '';
};
return Instruction;
}());
/**
* a resolved instruction has an outlet instruction for itself, but maybe not for...
*/
var ResolvedInstruction = (function (_super) {
__extends(ResolvedInstruction, _super);
function ResolvedInstruction(component, child, auxInstruction) {
_super.call(this, component, child, auxInstruction);
}
ResolvedInstruction.prototype.resolveComponent = function () {
return PromiseWrapper.resolve(this.component);
};
return ResolvedInstruction;
}(Instruction));
/**
* Represents a resolved default route
*/
var DefaultInstruction = (function (_super) {
__extends(DefaultInstruction, _super);
function DefaultInstruction(component, child) {
_super.call(this, component, child, {});
}
DefaultInstruction.prototype.toLinkUrl = function () { return ''; };
/** @internal */
DefaultInstruction.prototype._toLinkUrl = function () { return ''; };
return DefaultInstruction;
}(ResolvedInstruction));
/**
* Represents a component that may need to do some redirection or lazy loading at a later time.
*/
var UnresolvedInstruction = (function (_super) {
__extends(UnresolvedInstruction, _super);
function UnresolvedInstruction(_resolver, _urlPath, _urlParams) {
if (_urlPath === void 0) { _urlPath = ''; }
if (_urlParams === void 0) { _urlParams = []; }
_super.call(this, null, null, {});
this._resolver = _resolver;
this._urlPath = _urlPath;
this._urlParams = _urlParams;
}
Object.defineProperty(UnresolvedInstruction.prototype, "urlPath", {
get: function () {
if (isPresent(this.component)) {
return this.component.urlPath;
}
if (isPresent(this._urlPath)) {
return this._urlPath;
}
return '';
},
enumerable: true,
configurable: true
});
Object.defineProperty(UnresolvedInstruction.prototype, "urlParams", {
get: function () {
if (isPresent(this.component)) {
return this.component.urlParams;
}
if (isPresent(this._urlParams)) {
return this._urlParams;
}
return [];
},
enumerable: true,
configurable: true
});
UnresolvedInstruction.prototype.resolveComponent = function () {
var _this = this;
if (isPresent(this.component)) {
return PromiseWrapper.resolve(this.component);
}
return this._resolver().then(function (instruction) {
_this.child = isPresent(instruction) ? instruction.child : null;
return _this.component = isPresent(instruction) ? instruction.component : null;
});
};
return UnresolvedInstruction;
}(Instruction));
var RedirectInstruction = (function (_super) {
__extends(RedirectInstruction, _super);
function RedirectInstruction(component, child, auxInstruction, _specificity) {
_super.call(this, component, child, auxInstruction);
this._specificity = _specificity;
}
Object.defineProperty(RedirectInstruction.prototype, "specificity", {
get: function () { return this._specificity; },
enumerable: true,
configurable: true
});
return RedirectInstruction;
}(ResolvedInstruction));
/**
* A `ComponentInstruction` represents the route state for a single component.
*
* `ComponentInstructions` is a public API. Instances of `ComponentInstruction` are passed
* to route lifecycle hooks, like {@link CanActivate}.
*
* `ComponentInstruction`s are [hash consed](https://en.wikipedia.org/wiki/Hash_consing). You should
* never construct one yourself with "new." Instead, rely on router's internal recognizer to
* construct `ComponentInstruction`s.
*
* You should not modify this object. It should be treated as immutable.
*/
var ComponentInstruction = (function () {
/**
* @internal
*/
function ComponentInstruction(urlPath, urlParams, data, componentType /** TODO #9100 */, terminal, specificity, params, routeName) {
if (params === void 0) { params = null; }
this.urlPath = urlPath;
this.urlParams = urlParams;
this.componentType = componentType;
this.terminal = terminal;
this.specificity = specificity;
this.params = params;
this.routeName = routeName;
this.reuse = false;
this.routeData = isPresent(data) ? data : BLANK_ROUTE_DATA;
}
return ComponentInstruction;
}());
var makeDecorator = _angular_core.__core_private__.makeDecorator;
var reflector = _angular_core.__core_private__.reflector;
/* @ts2dart_const */
var RouteLifecycleHook = (function () {
function RouteLifecycleHook(name) {
this.name = name;
}
return RouteLifecycleHook;
}());
/* @ts2dart_const */
var CanActivateAnnotation = (function () {
function CanActivateAnnotation(fn) {
this.fn = fn;
}
return CanActivateAnnotation;
}());
var routerCanReuse =
/*@ts2dart_const*/ new RouteLifecycleHook('routerCanReuse');
var routerCanDeactivate =
/*@ts2dart_const*/ new RouteLifecycleHook('routerCanDeactivate');
var routerOnActivate =
/*@ts2dart_const*/ new RouteLifecycleHook('routerOnActivate');
var routerOnReuse =
/*@ts2dart_const*/ new RouteLifecycleHook('routerOnReuse');
var routerOnDeactivate =
/*@ts2dart_const*/ new RouteLifecycleHook('routerOnDeactivate');
function hasLifecycleHook(e, type /** TODO #9100 */) {
if (!(type instanceof _angular_core.Type))
return false;
return e.name in type.prototype;
}
function getCanActivateHook(type /** TODO #9100 */) {
var annotations = reflector.annotations(type);
for (var i = 0; i < annotations.length; i += 1) {
var annotation = annotations[i];
if (annotation instanceof CanActivateAnnotation) {
return annotation.fn;
}
}
return null;
}
/**
* The `RouteConfig` decorator defines routes for a given component.
*
* It takes an array of {@link RouteDefinition}s.
* @ts2dart_const
*/
var RouteConfigAnnotation = (function () {
function RouteConfigAnnotation(configs) {
this.configs = configs;
}
return RouteConfigAnnotation;
}());
/* @ts2dart_const */
var AbstractRoute = (function () {
function AbstractRoute(_a) {
var name = _a.name, useAsDefault = _a.useAsDefault, path = _a.path, regex = _a.regex, regex_group_names = _a.regex_group_names, serializer = _a.serializer, data = _a.data;
this.name = name;
this.useAsDefault = useAsDefault;
this.path = path;
this.regex = regex;
this.regex_group_names = regex_group_names;
this.serializer = serializer;
this.data = data;
}
return AbstractRoute;
}());
/**
* `Route` is a type of {@link RouteDefinition} used to route a path to a component.
*
* It has the following properties:
* - `path` is a string that uses the route matcher DSL.
* - `component` a component type.
* - `name` is an optional `CamelCase` string representing the name of the route.
* - `data` is an optional property of any type representing arbitrary route metadata for the given
* route. It is injectable via {@link RouteData}.
* - `useAsDefault` is a boolean value. If `true`, the child route will be navigated to if no child
* route is specified during the navigation.
*
* ### Example
* ```
* import {RouteConfig, Route} from '@angular/router-deprecated';
*
* @RouteConfig([
* new Route({path: '/home', component: HomeCmp, name: 'HomeCmp' })
* ])
* class MyApp {}
* ```
* @ts2dart_const
*/
var Route = (function (_super) {
__extends(Route, _super);
function Route(_a) {
var name = _a.name, useAsDefault = _a.useAsDefault, path = _a.path, regex = _a.regex, regex_group_names = _a.regex_group_names, serializer = _a.serializer, data = _a.data, component = _a.component;
_super.call(this, {
name: name,
useAsDefault: useAsDefault,
path: path,
regex: regex,
regex_group_names: regex_group_names,
serializer: serializer,
data: data
});
this.aux = null;
this.component = component;
}
return Route;
}(AbstractRoute));
/**
* `AuxRoute` is a type of {@link RouteDefinition} used to define an auxiliary route.
*
* It takes an object with the following properties:
* - `path` is a string that uses the route matcher DSL.
* - `component` a component type.
* - `name` is an optional `CamelCase` string representing the name of the route.
* - `data` is an optional property of any type representing arbitrary route metadata for the given
* route. It is injectable via {@link RouteData}.
*
* ### Example
* ```
* import {RouteConfig, AuxRoute} from '@angular/router-deprecated';
*
* @RouteConfig([
* new AuxRoute({path: '/home', component: HomeCmp})
* ])
* class MyApp {}
* ```
* @ts2dart_const
*/
var AuxRoute = (function (_super) {
__extends(AuxRoute, _super);
function AuxRoute(_a) {
var name = _a.name, useAsDefault = _a.useAsDefault, path = _a.path, regex = _a.regex, regex_group_names = _a.regex_group_names, serializer = _a.serializer, data = _a.data, component = _a.component;
_super.call(this, {
name: name,
useAsDefault: useAsDefault,
path: path,
regex: regex,
regex_group_names: regex_group_names,
serializer: serializer,
data: data
});
this.component = component;
}
return AuxRoute;
}(AbstractRoute));
/**
* `AsyncRoute` is a type of {@link RouteDefinition} used to route a path to an asynchronously
* loaded component.
*
* It has the following properties:
* - `path` is a string that uses the route matcher DSL.
* - `loader` is a function that returns a promise that resolves to a component.
* - `name` is an optional `CamelCase` string representing the name of the route.
* - `data` is an optional property of any type representing arbitrary route metadata for the given
* route. It is injectable via {@link RouteData}.
* - `useAsDefault` is a boolean value. If `true`, the child route will be navigated to if no child
* route is specified during the navigation.
*
* ### Example
* ```
* import {RouteConfig, AsyncRoute} from '@angular/router-deprecated';
*
* @RouteConfig([
* new AsyncRoute({path: '/home', loader: () => Promise.resolve(MyLoadedCmp), name:
* 'MyLoadedCmp'})
* ])
* class MyApp {}
* ```
* @ts2dart_const
*/
var AsyncRoute = (function (_super) {
__extends(AsyncRoute, _super);
function AsyncRoute(_a) {
var name = _a.name, useAsDefault = _a.useAsDefault, path = _a.path, regex = _a.regex, regex_group_names = _a.regex_group_names, serializer = _a.serializer, data = _a.data, loader = _a.loader;
_super.call(this, {
name: name,
useAsDefault: useAsDefault,
path: path,
regex: regex,
regex_group_names: regex_group_names,
serializer: serializer,
data: data
});
this.aux = null;
this.loader = loader;
}
return AsyncRoute;
}(AbstractRoute));
/**
* `Redirect` is a type of {@link RouteDefinition} used to route a path to a canonical route.
*
* It has the following properties:
* - `path` is a string that uses the route matcher DSL.
* - `redirectTo` is an array representing the link DSL.
*
* Note that redirects **do not** affect how links are generated. For that, see the `useAsDefault`
* option.
*
* ### Example
* ```
* import {RouteConfig, Route, Redirect} from '@angular/router-deprecated';
*
* @RouteConfig([
* new Redirect({path: '/', redirectTo: ['/Home'] }),
* new Route({path: '/home', component: HomeCmp, name: 'Home'})
* ])
* class MyApp {}
* ```
* @ts2dart_const
*/
var Redirect = (function (_super) {
__extends(Redirect, _super);
function Redirect(_a) {
var name = _a.name, useAsDefault = _a.useAsDefault, path = _a.path, regex = _a.regex, regex_group_names = _a.regex_group_names, serializer = _a.serializer, data = _a.data, redirectTo = _a.redirectTo;
_super.call(this, {
name: name,
useAsDefault: useAsDefault,
path: path,
regex: regex,
regex_group_names: regex_group_names,
serializer: serializer,
data: data
});
this.redirectTo = redirectTo;
}
return Redirect;
}(AbstractRoute));
function convertUrlParamsToArray(urlParams) {
var paramsArray = [];
if (isBlank(urlParams)) {
return [];
}
StringMapWrapper.forEach(urlParams, function (value /** TODO #9100 */, key /** TODO #9100 */) {
paramsArray.push((value === true) ? key : key + '=' + value);
});
return paramsArray;
}
// Convert an object of url parameters into a string that can be used in an URL
function serializeParams(urlParams, joiner) {
if (joiner === void 0) { joiner = '&'; }
return convertUrlParamsToArray(urlParams).join(joiner);
}
/**
* This class represents a parsed URL
*/
var Url = (function () {
function Url(path, child, auxiliary, params) {
if (child === void 0) { child = null; }
if (auxiliary === void 0) { auxiliary = []; }
if (params === void 0) { params = {}; }
this.path = path;
this.child = child;
this.auxiliary = auxiliary;
this.params = params;
}
Url.prototype.toString = function () {
return this.path + this._matrixParamsToString() + this._auxToString() + this._childString();
};
Url.prototype.segmentToString = function () { return this.path + this._matrixParamsToString(); };
/** @internal */
Url.prototype._auxToString = function () {
return this.auxiliary.length > 0 ?
('(' + this.auxiliary.map(function (sibling) { return sibling.toString(); }).join('//') + ')') :
'';
};
Url.prototype._matrixParamsToString = function () {
var paramString = serializeParams(this.params, ';');
if (paramString.length > 0) {
return ';' + paramString;
}
return '';
};
/** @internal */
Url.prototype._childString = function () { return isPresent(this.child) ? ('/' + this.child.toString()) : ''; };
return Url;
}());
var RootUrl = (function (_super) {
__extends(RootUrl, _super);
function RootUrl(path, child, auxiliary, params) {
if (c