Socket
Socket
Sign inDemoInstall

@angular/router

Package Overview
Dependencies
Maintainers
1
Versions
855
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@angular/router - npm Package Compare versions

Comparing version 2.0.0-rc.0 to 2.0.0-rc.1

esm/src/facade/base_wrapped_exception.d.ts

22

esm/index.d.ts
/**
* @module
* @description
* Alternative implementation of the router. Experimental.
* Maps application URLs into application states, to support deep-linking and navigation.
*/

@@ -13,2 +13,22 @@ export { Router, RouterOutletMap } from './src/router';

export { ROUTER_PROVIDERS } from './src/router_providers';
/**
* A list of directives. To use the router directives like {@link RouterOutlet} and
* {@link RouterLink}, add this to your `directives` array in the {@link View} decorator of your
* component.
*
* ```
* import {Component} from '@angular/core';
* import {ROUTER_DIRECTIVES, Routes} from '@angular/router-deprecated';
*
* @Component({directives: [ROUTER_DIRECTIVES]})
* @RouteConfig([
* {...},
* ])
* class AppCmp {
* // ...
* }
*
* bootstrap(AppCmp);
* ```
*/
export declare const ROUTER_DIRECTIVES: any[];
/**
* @module
* @description
* Alternative implementation of the router. Experimental.
* Maps application URLs into application states, to support deep-linking and navigation.
*/

@@ -14,3 +14,23 @@ export { Router, RouterOutletMap } from './src/router';

import { RouterLink } from './src/directives/router_link';
/**
* A list of directives. To use the router directives like {@link RouterOutlet} and
* {@link RouterLink}, add this to your `directives` array in the {@link View} decorator of your
* component.
*
* ```
* import {Component} from '@angular/core';
* import {ROUTER_DIRECTIVES, Routes} from '@angular/router-deprecated';
*
* @Component({directives: [ROUTER_DIRECTIVES]})
* @RouteConfig([
* {...},
* ])
* class AppCmp {
* // ...
* }
*
* bootstrap(AppCmp);
* ```
*/
export const ROUTER_DIRECTIVES = [RouterOutlet, RouterLink];
//# sourceMappingURL=index.js.map

@@ -0,1 +1,5 @@

/**
* Name of the default outlet outlet.
* @type {string}
*/
export declare const DEFAULT_OUTLET_NAME: string;

@@ -0,2 +1,6 @@

/**
* Name of the default outlet outlet.
* @type {string}
*/
export const DEFAULT_OUTLET_NAME = "__DEFAULT";
//# sourceMappingURL=constants.js.map
import { OnDestroy } from '@angular/core';
import { Router } from '../router';
import { RouteSegment } from '../segments';
/**
* The RouterLink directive lets you link to specific parts of your app.
*
* Consider the following route configuration:
* ```
* @Routes([
* { path: '/user', component: UserCmp }
* ]);
* class MyComp {}
* ```
*
* When linking to this `User` route, you can write:
*
* ```
* <a [routerLink]="['/user']">link to user component</a>
* ```
*
* RouterLink expects the value to be an array of path segments, followed by the params
* for that level of routing. For instance `['/team', {teamId: 1}, 'user', {userId: 2}]`
* means that we want to generate a link to `/team;teamId=1/user;userId=2`.
*
* The first segment name can be prepended with `/`, `./`, or `../`.
* If the segment begins with `/`, the router will look up the route from the root of the app.
* If the segment begins with `./`, or doesn't begin with a slash, the router will
* instead look in the current component's children for the route.
* And if the segment begins with `../`, the router will go up one segment in the url.
*
* See {@link Router.createUrlTree} for more information.
*/
export declare class RouterLink implements OnDestroy {

@@ -8,11 +38,11 @@ private _routeSegment;

target: string;
private _changes;
private _commands;
private _subscription;
private href;
private isActive;
href: string;
isActive: boolean;
constructor(_routeSegment: RouteSegment, _router: Router);
ngOnDestroy(): void;
routerLink: any[];
routerLink: any[] | any;
onClick(): boolean;
private _updateTargetUrlAndHref();
}

18

esm/src/directives/router_link.js
import { Directive, HostListener, HostBinding, Input, Optional } from '@angular/core';
import { Router } from '../router';
import { RouteSegment } from '../segments';
import { isString, isPresent } from '../facade/lang';
import { isString, isArray, isPresent } from '../facade/lang';
import { ObservableWrapper } from '../facade/async';

@@ -10,4 +10,6 @@ export class RouterLink {

this._router = _router;
this._changes = [];
this._commands = [];
this.isActive = false;
// because auxiliary links take existing primary and auxiliary routes into account,
// we need to update the link whenever params or other routes change.
this._subscription =

@@ -18,8 +20,14 @@ ObservableWrapper.subscribe(_router.changes, (_) => { this._updateTargetUrlAndHref(); });

set routerLink(data) {
this._changes = data;
if (isArray(data)) {
this._commands = data;
}
else {
this._commands = [data];
}
this._updateTargetUrlAndHref();
}
onClick() {
// If no target, or if target is _self, prevent default browser behavior
if (!isString(this.target) || this.target == '_self') {
this._router.navigate(this._changes, this._routeSegment);
this._router.navigate(this._commands, this._routeSegment);
return false;

@@ -30,3 +38,3 @@ }

_updateTargetUrlAndHref() {
let tree = this._router.createUrlTree(this._changes, this._routeSegment);
let tree = this._router.createUrlTree(this._commands, this._routeSegment);
if (isPresent(tree)) {

@@ -33,0 +41,0 @@ this.href = this._router.serializeUrl(tree);

import { ResolvedReflectiveProvider, ViewContainerRef, ComponentRef, ComponentFactory } from '@angular/core';
import { RouterOutletMap } from '../router';
/**
* A router outlet is a placeholder that Angular dynamically fills based on the application's route.
*
* ## Use
*
* ```
* <router-outlet></router-outlet>
* ```
*
* Outlets can be named.
*
* ```
* <router-outlet name="right"></router-outlet>
* ```
*/
export declare class RouterOutlet {

@@ -9,5 +24,14 @@ private _location;

unload(): void;
/**
* Returns the loaded component.
*/
readonly loadedComponent: Object;
/**
* Returns true is the outlet is not empty.
*/
readonly isLoaded: boolean;
/**
* Called by the Router to instantiate a new component.
*/
load(factory: ComponentFactory<any>, providers: ResolvedReflectiveProvider[], outletMap: RouterOutletMap): ComponentRef<any>;
}

@@ -14,4 +14,13 @@ import { Directive, ViewContainerRef, Attribute, ReflectiveInjector } from '@angular/core';

}
/**
* Returns the loaded component.
*/
get loadedComponent() { return isPresent(this._loaded) ? this._loaded.instance : null; }
/**
* Returns true is the outlet is not empty.
*/
get isLoaded() { return isPresent(this._loaded); }
/**
* Called by the Router to instantiate a new component.
*/
load(factory, providers, outletMap) {

@@ -18,0 +27,0 @@ this.outletMap = outletMap;

import { RouteSegment, RouteTree } from './segments';
/**
* Defines route lifecycle method `routerOnActivate`, which is called by the router at the end of a
* successful route navigation.
*
* The `routerOnActivate` hook is called with the current and previous {@link RouteSegment}s of the
* component and with the corresponding route trees.
*/
export interface OnActivate {
routerOnActivate(curr: RouteSegment, prev?: RouteSegment, currTree?: RouteTree, prevTree?: RouteTree): void;
}
/**
* Defines route lifecycle method `routerOnDeactivate`, which is called by the router before
* destroying a component as part of a route change.
*
* The `routerOnDeactivate` hook is called with two {@link RouteTree}s, representing the current
* and the future state of the application.
*
* `routerOnDeactivate` must return a promise. The route change will wait until the promise settles.
*/
export interface CanDeactivate {
routerCanDeactivate(currTree?: RouteTree, futureTree?: RouteTree): Promise<boolean>;
}
import { RouteSegment, UrlTree, RouteTree } from './segments';
export declare function link(segment: RouteSegment, routeTree: RouteTree, urlTree: UrlTree, change: any[]): UrlTree;
export declare function link(segment: RouteSegment, routeTree: RouteTree, urlTree: UrlTree, commands: any[]): UrlTree;
import { TreeNode, UrlSegment, rootNode, UrlTree } from './segments';
import { isBlank, isPresent, isString, isStringMap } from './facade/lang';
import { BaseException } from './facade/exceptions';
import { ListWrapper } from './facade/collection';
export function link(segment, routeTree, urlTree, change) {
if (change.length === 0)
// TODO: vsavkin: should reuse segments
export function link(segment, routeTree, urlTree, commands) {
if (commands.length === 0)
return urlTree;
let startingNode;
let normalizedChange;
if (isString(change[0]) && change[0].startsWith("./")) {
normalizedChange = ["/", change[0].substring(2)].concat(change.slice(1));
startingNode = _findStartingNode(_findUrlSegment(segment, routeTree), rootNode(urlTree));
let normalizedCommands = _normalizeCommands(commands);
if (_navigateToRoot(normalizedCommands)) {
return new UrlTree(new TreeNode(urlTree.root, []));
}
else if (isString(change[0]) && change.length === 1 && change[0] == "/") {
normalizedChange = change;
startingNode = rootNode(urlTree);
let startingNode = _findStartingNode(normalizedCommands, urlTree, segment, routeTree);
let updated = normalizedCommands.commands.length > 0 ?
_updateMany(ListWrapper.clone(startingNode.children), normalizedCommands.commands) : [];
let newRoot = _constructNewTree(rootNode(urlTree), startingNode, updated);
return new UrlTree(newRoot);
}
function _navigateToRoot(normalizedChange) {
return normalizedChange.isAbsolute && normalizedChange.commands.length === 1 && normalizedChange.commands[0] == "/";
}
class _NormalizedNavigationCommands {
constructor(isAbsolute, numberOfDoubleDots, commands) {
this.isAbsolute = isAbsolute;
this.numberOfDoubleDots = numberOfDoubleDots;
this.commands = commands;
}
else if (isString(change[0]) && !change[0].startsWith("/")) {
normalizedChange = ["/"].concat(change);
startingNode = _findStartingNode(_findUrlSegment(segment, routeTree), rootNode(urlTree));
}
function _normalizeCommands(commands) {
;
'';
if (isString(commands[0]) && commands.length === 1 && commands[0] == "/") {
return new _NormalizedNavigationCommands(true, 0, commands);
}
else {
normalizedChange = ["/"].concat(change);
startingNode = rootNode(urlTree);
let numberOfDoubleDots = 0;
let isAbsolute = false;
let res = [];
for (let i = 0; i < commands.length; ++i) {
let c = commands[i];
if (!isString(c)) {
res.push(c);
continue;
}
let parts = c.split('/');
for (let j = 0; j < parts.length; ++j) {
let cc = parts[j];
// first exp is treated in a special way
if (i == 0) {
if (j == 0 && cc == ".") {
}
else if (j == 0 && cc == "") {
isAbsolute = true;
}
else if (cc == "..") {
numberOfDoubleDots++;
}
else if (cc != '') {
res.push(cc);
}
}
else {
if (cc != '') {
res.push(cc);
}
}
}
}
let updated = _update(startingNode, normalizedChange);
let newRoot = _constructNewTree(rootNode(urlTree), startingNode, updated);
return new UrlTree(newRoot);
return new _NormalizedNavigationCommands(isAbsolute, numberOfDoubleDots, res);
}
function _findUrlSegment(segment, routeTree) {
function _findUrlSegment(segment, routeTree, urlTree, numberOfDoubleDots) {
let s = segment;
let res = null;
while (isBlank(res)) {
res = ListWrapper.last(s.urlSegments);
while (s.urlSegments.length === 0) {
s = routeTree.parent(s);
}
return res;
let urlSegment = ListWrapper.last(s.urlSegments);
let path = urlTree.pathFromRoot(urlSegment);
if (path.length <= numberOfDoubleDots) {
throw new BaseException("Invalid number of '../'");
}
return path[path.length - 1 - numberOfDoubleDots];
}
function _findStartingNode(segment, node) {
function _findStartingNode(normalizedChange, urlTree, segment, routeTree) {
if (normalizedChange.isAbsolute) {
return rootNode(urlTree);
}
else {
let urlSegment = _findUrlSegment(segment, routeTree, urlTree, normalizedChange.numberOfDoubleDots);
return _findMatchingNode(urlSegment, rootNode(urlTree));
}
}
function _findMatchingNode(segment, node) {
if (node.value === segment)
return node;
for (var c of node.children) {
let r = _findStartingNode(segment, c);
let r = _findMatchingNode(segment, c);
if (isPresent(r))

@@ -50,3 +103,3 @@ return r;

if (node === original) {
return new TreeNode(node.value, updated.children);
return new TreeNode(node.value, updated);
}

@@ -57,50 +110,63 @@ else {

}
function _update(node, changes) {
let rest = changes.slice(1);
let outlet = _outlet(changes);
let segment = _segment(changes);
if (isString(segment) && segment[0] == "/")
segment = segment.substring(1);
function _update(node, commands) {
let rest = commands.slice(1);
let next = rest.length === 0 ? null : rest[0];
let outlet = _outlet(commands);
let segment = _segment(commands);
// reach the end of the tree => create new tree nodes.
if (isBlank(node)) {
let urlSegment = new UrlSegment(segment, null, outlet);
if (isBlank(node) && !isStringMap(next)) {
let urlSegment = new UrlSegment(segment, {}, outlet);
let children = rest.length === 0 ? [] : [_update(null, rest)];
return new TreeNode(urlSegment, children);
}
else if (isBlank(node) && isStringMap(next)) {
let urlSegment = new UrlSegment(segment, next, outlet);
return _recurse(urlSegment, node, rest.slice(1));
}
else if (outlet != node.value.outlet) {
return node;
}
else if (isStringMap(segment)) {
let newSegment = new UrlSegment(node.value.segment, segment, node.value.outlet);
return _recurse(newSegment, node, rest);
}
else if (isStringMap(next)) {
let urlSegment = new UrlSegment(segment, next, outlet);
return _recurse(urlSegment, node, rest.slice(1));
}
else {
let urlSegment = isStringMap(segment) ? new UrlSegment(null, segment, null) :
new UrlSegment(segment, null, outlet);
if (rest.length === 0) {
return new TreeNode(urlSegment, []);
}
return new TreeNode(urlSegment, _updateMany(ListWrapper.clone(node.children), rest));
let urlSegment = new UrlSegment(segment, {}, outlet);
return _recurse(urlSegment, node, rest);
}
}
function _updateMany(nodes, changes) {
let outlet = _outlet(changes);
function _recurse(urlSegment, node, rest) {
if (rest.length === 0) {
return new TreeNode(urlSegment, []);
}
return new TreeNode(urlSegment, _updateMany(ListWrapper.clone(node.children), rest));
}
function _updateMany(nodes, commands) {
let outlet = _outlet(commands);
let nodesInRightOutlet = nodes.filter(c => c.value.outlet == outlet);
if (nodesInRightOutlet.length > 0) {
let nodeRightOutlet = nodesInRightOutlet[0]; // there can be only one
nodes[nodes.indexOf(nodeRightOutlet)] = _update(nodeRightOutlet, changes);
nodes[nodes.indexOf(nodeRightOutlet)] = _update(nodeRightOutlet, commands);
}
else {
nodes.push(_update(null, changes));
nodes.push(_update(null, commands));
}
return nodes;
}
function _segment(changes) {
if (!isString(changes[0]))
return changes[0];
let parts = changes[0].toString().split(":");
return parts.length > 1 ? parts[1] : changes[0];
function _segment(commands) {
if (!isString(commands[0]))
return commands[0];
let parts = commands[0].toString().split(":");
return parts.length > 1 ? parts[1] : commands[0];
}
function _outlet(changes) {
if (!isString(changes[0]))
function _outlet(commands) {
if (!isString(commands[0]))
return null;
let parts = changes[0].toString().split(":");
let parts = commands[0].toString().split(":");
return parts.length > 1 ? parts[0] : null;
}
//# sourceMappingURL=link.js.map
import { RoutesMetadata, RouteMetadata } from "./metadata";
/**
* Defines routes for a given component.
*
* It takes an array of {@link RouteMetadata}s.
*/
export interface RoutesFactory {

@@ -6,2 +11,7 @@ (routes: RouteMetadata[]): any;

}
/**
* Defines routes for a given component.
*
* It takes an array of {@link RouteMetadata}s.
*/
export declare var Routes: RoutesFactory;
import { RoutesMetadata } from "./metadata";
import { makeDecorator } from '../core_private';
/**
* Defines routes for a given component.
*
* It takes an array of {@link RouteMetadata}s.
*/
export var Routes = makeDecorator(RoutesMetadata);
//# sourceMappingURL=decorators.js.map
import { Type } from '@angular/core';
/**
* Information about a route.
*
* It has the following properties:
* - `path` is a string that uses the route matcher DSL.
* - `component` a component type.
*
* ### Example
* ```
* import {Routes} from '@angular/router';
*
* @Routes([
* {path: '/home', component: HomeCmp}
* ])
* class MyApp {}
* ```
*
* @ts2dart_const
*/
export declare abstract class RouteMetadata {

@@ -6,2 +25,6 @@ readonly abstract path: string;

}
/**
* See {@link RouteMetadata} for more information.
* @ts2dart_const
*/
export declare class Route implements RouteMetadata {

@@ -16,2 +39,8 @@ path: string;

}
/**
* Defines routes for a given component.
*
* It takes an array of {@link RouteMetadata}s.
* @ts2dart_const
*/
export declare class RoutesMetadata {

@@ -18,0 +47,0 @@ routes: RouteMetadata[];

import { stringify } from "../facade/lang";
/**
* Information about a route.
*
* It has the following properties:
* - `path` is a string that uses the route matcher DSL.
* - `component` a component type.
*
* ### Example
* ```
* import {Routes} from '@angular/router';
*
* @Routes([
* {path: '/home', component: HomeCmp}
* ])
* class MyApp {}
* ```
*
* @ts2dart_const
*/
export class RouteMetadata {

@@ -6,3 +25,6 @@ get path() { }

}
/* @ts2dart_const */
/**
* See {@link RouteMetadata} for more information.
* @ts2dart_const
*/
export class Route {

@@ -15,3 +37,8 @@ constructor({ path, component } = {}) {

}
/* @ts2dart_const */
/**
* Defines routes for a given component.
*
* It takes an array of {@link RouteMetadata}s.
* @ts2dart_const
*/
export class RoutesMetadata {

@@ -18,0 +45,0 @@ constructor(routes) {

@@ -11,3 +11,3 @@ import { RouteSegment, TreeNode, rootNode, RouteTree } from './segments';

export function recognize(componentResolver, type, url) {
let matched = new _MatchResult(type, [url.root], null, rootNode(url).children, []);
let matched = new _MatchResult(type, [url.root], {}, rootNode(url).children, []);
return _constructSegment(componentResolver, matched).then(roots => new RouteTree(roots[0]));

@@ -69,3 +69,3 @@ }

.then(factory => {
let segment = new RouteSegment([], null, DEFAULT_OUTLET_NAME, r[0].component, factory);
let segment = new RouteSegment([], {}, DEFAULT_OUTLET_NAME, r[0].component, factory);
return [new TreeNode(segment, children)];

@@ -119,8 +119,4 @@ });

}
if (isPresent(current) && isBlank(current.value.segment)) {
lastParent = lastSegment;
lastSegment = current;
}
let p = lastSegment.value.parameters;
let parameters = StringMapWrapper.merge(isBlank(p) ? {} : p, positionalParams);
let parameters = StringMapWrapper.merge(p, positionalParams);
let axuUrlSubtrees = isPresent(lastParent) ? lastParent.children.slice(1) : [];

@@ -127,0 +123,0 @@ return new _MatchResult(route.component, consumedUrlSegments, parameters, lastSegment.children, axuUrlSubtrees);

@@ -0,1 +1,4 @@

/**
* The Platform agnostic ROUTER PROVIDERS
*/
export declare const ROUTER_PROVIDERS_COMMON: any[];

@@ -7,2 +7,5 @@ import { ComponentResolver } from '@angular/core';

import { BaseException } from '@angular/core';
/**
* The Platform agnostic ROUTER PROVIDERS
*/
export const ROUTER_PROVIDERS_COMMON = [

@@ -9,0 +12,0 @@ RouterOutletMap,

@@ -0,1 +1,23 @@

/**
* A list of {@link Provider}s. To use the router, you must add this to your application.
*
* ```
* import {Component} from '@angular/core';
* import {
* ROUTER_DIRECTIVES,
* ROUTER_PROVIDERS,
* Routes
* } from '@angular/router';
*
* @Component({directives: [ROUTER_DIRECTIVES]})
* @Routes([
* {...},
* ])
* class AppCmp {
* // ...
* }
*
* bootstrap(AppCmp, [ROUTER_PROVIDERS]);
* ```
*/
export declare const ROUTER_PROVIDERS: any[];
import { ROUTER_PROVIDERS_COMMON } from './router_providers_common';
import { BrowserPlatformLocation } from '@angular/platform-browser';
import { PlatformLocation } from '@angular/common';
/**
* A list of {@link Provider}s. To use the router, you must add this to your application.
*
* ```
* import {Component} from '@angular/core';
* import {
* ROUTER_DIRECTIVES,
* ROUTER_PROVIDERS,
* Routes
* } from '@angular/router';
*
* @Component({directives: [ROUTER_DIRECTIVES]})
* @Routes([
* {...},
* ])
* class AppCmp {
* // ...
* }
*
* bootstrap(AppCmp, [ROUTER_PROVIDERS]);
* ```
*/
export const ROUTER_PROVIDERS = [

@@ -5,0 +27,0 @@ ROUTER_PROVIDERS_COMMON,

import { UrlTree } from './segments';
/**
* Defines a way to serialize/deserialize a url tree.
*/
export declare abstract class RouterUrlSerializer {
/**
* Parse a url into a {@Link UrlTree}
*/
abstract parse(url: string): UrlTree;
/**
* Converts a {@Link UrlTree} into a url
*/
abstract serialize(tree: UrlTree): string;
}
/**
* A default implementation of the serialization.
*/
export declare class DefaultRouterUrlSerializer extends RouterUrlSerializer {

@@ -7,0 +19,0 @@ parse(url: string): UrlTree;

import { UrlSegment, TreeNode, rootNode, UrlTree } from './segments';
import { BaseException } from '@angular/core';
import { isBlank, isPresent, RegExpWrapper } from './facade/lang';
/**
* Defines a way to serialize/deserialize a url tree.
*/
export class RouterUrlSerializer {
}
/**
* A default implementation of the serialization.
*/
export class DefaultRouterUrlSerializer extends RouterUrlSerializer {

@@ -25,4 +31,3 @@ parse(url) {

if (node.children.length > 0) {
let slash = isBlank(node.children[0].value.segment) ? "" : "/";
return `${slash}${_serializeUrlTreeNodes(node.children)}`;
return `/${_serializeUrlTreeNodes(node.children)}`;
}

@@ -54,3 +59,3 @@ else {

if (url == '' || url == '/') {
return new TreeNode(new UrlSegment('', null, null), []);
return new TreeNode(new UrlSegment('', {}, null), []);
}

@@ -63,4 +68,3 @@ else {

let segments = this.parseSegments();
let queryParams = this.peekStartsWith('?') ? this.parseQueryParams() : null;
return new TreeNode(new UrlSegment('', queryParams, null), segments);
return new TreeNode(new UrlSegment('', {}, null), segments);
}

@@ -81,3 +85,3 @@ parseSegments(outletName = null) {

}
var matrixParams = null;
var matrixParams = {};
if (this.peekStartsWith(';')) {

@@ -95,13 +99,5 @@ matrixParams = this.parseMatrixParams();

}
if (isPresent(matrixParams)) {
let matrixParamsSegment = new UrlSegment(null, matrixParams, null);
let matrixParamsNode = new TreeNode(matrixParamsSegment, children);
let segment = new UrlSegment(path, null, outletName);
return [new TreeNode(segment, [matrixParamsNode].concat(aux))];
}
else {
let segment = new UrlSegment(path, null, outletName);
let node = new TreeNode(segment, children);
return [node].concat(aux);
}
let segment = new UrlSegment(path, matrixParams, outletName);
let node = new TreeNode(segment, children);
return [node].concat(aux);
}

@@ -108,0 +104,0 @@ parseQueryParams() {

@@ -8,2 +8,5 @@ import { ComponentResolver } from '@angular/core';

import { RouteSegment, UrlTree, RouteTree } from './segments';
/**
* @internal
*/
export declare class RouterOutletMap {

@@ -16,2 +19,8 @@ /** @internal */

}
/**
* The `Router` is responsible for mapping URLs to components.
*
* You can see the state of the router by inspecting the read-only fields `router.urlTree`
* and `router.routeTree`.
*/
export declare class Router {

@@ -28,14 +37,82 @@ private _rootComponent;

private _changes;
/**
* @internal
*/
constructor(_rootComponent: Object, _rootComponentType: Type, _componentResolver: ComponentResolver, _urlSerializer: RouterUrlSerializer, _routerOutletMap: RouterOutletMap, _location: Location);
/**
* Returns the current url tree.
*/
readonly urlTree: UrlTree;
/**
* Returns the current route tree.
*/
readonly routeTree: RouteTree;
/**
* An observable or url changes from the router.
*/
readonly changes: Observable<void>;
/**
* Navigate based on the provided url. This navigation is always absolute.
*
* ### Usage
*
* ```
* router.navigateByUrl("/team/33/user/11");
* ```
*/
navigateByUrl(url: string): Promise<void>;
navigate(changes: any[], segment?: RouteSegment): Promise<void>;
/**
* Navigate based on the provided array of commands and a starting point.
* If no segment is provided, the navigation is absolute.
*
* ### Usage
*
* ```
* router.navigate(['team', 33, 'team', '11], segment);
* ```
*/
navigate(commands: any[], segment?: RouteSegment): Promise<void>;
/**
* @internal
*/
dispose(): void;
/**
* Applies an array of commands to the current url tree and creates
* a new url tree.
*
* When given a segment, applies the given commands starting from the segment.
* When not given a segment, applies the given command starting from the root.
*
* ### Usage
*
* ```
* // create /team/33/user/11
* router.createUrlTree(['/team', 33, 'user', 11]);
*
* // create /team/33;expand=true/user/11
* router.createUrlTree(['/team', 33, {expand: true}, 'user', 11]);
*
* // you can collapse static fragments like this
* router.createUrlTree(['/team/33/user', userId]);
*
* // assuming the current url is `/team/33/user/11` and the segment points to `user/11`
*
* // navigate to /team/33/user/11/details
* router.createUrlTree(['details'], segment);
*
* // navigate to /team/33/user/22
* router.createUrlTree(['../22'], segment);
*
* // navigate to /team/44/user/22
* router.createUrlTree(['../../team/44/user/22'], segment);
* ```
*/
createUrlTree(commands: any[], segment?: RouteSegment): UrlTree;
/**
* Serializes a {@link UrlTree} into a string.
*/
serializeUrl(url: UrlTree): string;
private _createInitialTree();
private _setUpLocationChangeListener();
private _navigate(url);
createUrlTree(changes: any[], segment?: RouteSegment): UrlTree;
serializeUrl(url: UrlTree): string;
readonly changes: Observable<void>;
readonly routeTree: RouteTree;
}

@@ -12,2 +12,5 @@ import { provide, ReflectiveInjector } from '@angular/core';

import { DEFAULT_OUTLET_NAME } from './constants';
/**
* @internal
*/
export class RouterOutletMap {

@@ -20,3 +23,12 @@ constructor() {

}
/**
* The `Router` is responsible for mapping URLs to components.
*
* You can see the state of the router by inspecting the read-only fields `router.urlTree`
* and `router.routeTree`.
*/
export class Router {
/**
* @internal
*/
constructor(_rootComponent, _rootComponentType, _componentResolver, _urlSerializer, _routerOutletMap, _location) {

@@ -34,12 +46,84 @@ this._rootComponent = _rootComponent;

}
/**
* Returns the current url tree.
*/
get urlTree() { return this._urlTree; }
/**
* Returns the current route tree.
*/
get routeTree() { return this._prevTree; }
/**
* An observable or url changes from the router.
*/
get changes() { return this._changes; }
/**
* Navigate based on the provided url. This navigation is always absolute.
*
* ### Usage
*
* ```
* router.navigateByUrl("/team/33/user/11");
* ```
*/
navigateByUrl(url) {
return this._navigate(this._urlSerializer.parse(url));
}
navigate(changes, segment) {
return this._navigate(this.createUrlTree(changes, segment));
/**
* Navigate based on the provided array of commands and a starting point.
* If no segment is provided, the navigation is absolute.
*
* ### Usage
*
* ```
* router.navigate(['team', 33, 'team', '11], segment);
* ```
*/
navigate(commands, segment) {
return this._navigate(this.createUrlTree(commands, segment));
}
/**
* @internal
*/
dispose() { ObservableWrapper.dispose(this._locationSubscription); }
/**
* Applies an array of commands to the current url tree and creates
* a new url tree.
*
* When given a segment, applies the given commands starting from the segment.
* When not given a segment, applies the given command starting from the root.
*
* ### Usage
*
* ```
* // create /team/33/user/11
* router.createUrlTree(['/team', 33, 'user', 11]);
*
* // create /team/33;expand=true/user/11
* router.createUrlTree(['/team', 33, {expand: true}, 'user', 11]);
*
* // you can collapse static fragments like this
* router.createUrlTree(['/team/33/user', userId]);
*
* // assuming the current url is `/team/33/user/11` and the segment points to `user/11`
*
* // navigate to /team/33/user/11/details
* router.createUrlTree(['details'], segment);
*
* // navigate to /team/33/user/22
* router.createUrlTree(['../22'], segment);
*
* // navigate to /team/44/user/22
* router.createUrlTree(['../../team/44/user/22'], segment);
* ```
*/
createUrlTree(commands, segment) {
let s = isPresent(segment) ? segment : this._prevTree.root;
return link(s, this._prevTree, this.urlTree, commands);
}
/**
* Serializes a {@link UrlTree} into a string.
*/
serializeUrl(url) { return this._urlSerializer.serialize(url); }
_createInitialTree() {
let root = new RouteSegment([new UrlSegment("", null, null)], null, DEFAULT_OUTLET_NAME, this._rootComponentType, null);
let root = new RouteSegment([new UrlSegment("", {}, null)], {}, DEFAULT_OUTLET_NAME, this._rootComponentType, null);
return new RouteTree(new TreeNode(root, []));

@@ -65,14 +149,2 @@ }

}
createUrlTree(changes, segment) {
if (isPresent(this._prevTree)) {
let s = isPresent(segment) ? segment : this._prevTree.root;
return link(s, this._prevTree, this.urlTree, changes);
}
else {
return null;
}
}
serializeUrl(url) { return this._urlSerializer.serialize(url); }
get changes() { return this._changes; }
get routeTree() { return this._prevTree; }
}

@@ -79,0 +151,0 @@ class _LoadSegments {

@@ -28,7 +28,7 @@ import { ComponentFactory, Type } from '@angular/core';

parameters: {
[key: string]: string;
[key: string]: any;
};
outlet: string;
constructor(segment: any, parameters: {
[key: string]: string;
[key: string]: any;
}, outlet: string);

@@ -40,3 +40,3 @@ toString(): string;

parameters: {
[key: string]: string;
[key: string]: any;
};

@@ -49,3 +49,3 @@ outlet: string;

constructor(urlSegments: UrlSegment[], parameters: {
[key: string]: string;
[key: string]: any;
}, outlet: string, type: Type, componentFactory: ComponentFactory<any>);

@@ -52,0 +52,0 @@ getParam(param: string): string;

@@ -94,4 +94,3 @@ import { StringMapWrapper, ListWrapper } from './facade/collection';

let outletPrefix = isBlank(this.outlet) ? "" : `${this.outlet}:`;
let segmentPrefix = isBlank(this.segment) ? "" : this.segment;
return `${outletPrefix}${segmentPrefix}${_serializeParams(this.parameters)}`;
return `${outletPrefix}${this.segment}${_serializeParams(this.parameters)}`;
}

@@ -101,5 +100,3 @@ }

let res = "";
if (isPresent(params)) {
StringMapWrapper.forEach(params, (v, k) => res += `;${k}=${v}`);
}
StringMapWrapper.forEach(params, (v, k) => res += `;${k}=${v}`);
return res;

@@ -138,8 +135,2 @@ }

return false;
if (isBlank(a.parameters) && !isBlank(b.parameters))
return false;
if (!isBlank(a.parameters) && isBlank(b.parameters))
return false;
if (isBlank(a.parameters) && isBlank(b.parameters))
return true;
return StringMapWrapper.equals(a.parameters, b.parameters);

@@ -156,8 +147,8 @@ }

return false;
if (isBlank(a.parameters) && !isBlank(b.parameters))
return false;
if (!isBlank(a.parameters) && isBlank(b.parameters))
return false;
if (isBlank(a.parameters) && isBlank(b.parameters))
return true;
if (isBlank(a.parameters)) {
console.log("a", a);
}
if (isBlank(b.parameters)) {
console.log("b", b);
}
return StringMapWrapper.equals(a.parameters, b.parameters);

@@ -164,0 +155,0 @@ }

/**
* @module
* @description
* Alternative implementation of the router. Experimental.
* Maps application URLs into application states, to support deep-linking and navigation.
*/

@@ -13,2 +13,22 @@ export { Router, RouterOutletMap } from './src/router';

export { ROUTER_PROVIDERS } from './src/router_providers';
/**
* A list of directives. To use the router directives like {@link RouterOutlet} and
* {@link RouterLink}, add this to your `directives` array in the {@link View} decorator of your
* component.
*
* ```
* import {Component} from '@angular/core';
* import {ROUTER_DIRECTIVES, Routes} from '@angular/router-deprecated';
*
* @Component({directives: [ROUTER_DIRECTIVES]})
* @RouteConfig([
* {...},
* ])
* class AppCmp {
* // ...
* }
*
* bootstrap(AppCmp);
* ```
*/
export declare const ROUTER_DIRECTIVES: any[];

@@ -5,3 +5,3 @@ "use strict";

* @description
* Alternative implementation of the router. Experimental.
* Maps application URLs into application states, to support deep-linking and navigation.
*/

@@ -28,3 +28,23 @@ var router_1 = require('./src/router');

var router_link_1 = require('./src/directives/router_link');
/**
* A list of directives. To use the router directives like {@link RouterOutlet} and
* {@link RouterLink}, add this to your `directives` array in the {@link View} decorator of your
* component.
*
* ```
* import {Component} from '@angular/core';
* import {ROUTER_DIRECTIVES, Routes} from '@angular/router-deprecated';
*
* @Component({directives: [ROUTER_DIRECTIVES]})
* @RouteConfig([
* {...},
* ])
* class AppCmp {
* // ...
* }
*
* bootstrap(AppCmp);
* ```
*/
exports.ROUTER_DIRECTIVES = [router_outlet_1.RouterOutlet, router_link_1.RouterLink];
//# sourceMappingURL=index.js.map
{
"name": "@angular/router",
"version": "2.0.0-rc.0",
"version": "2.0.0-rc.1",
"description": "",

@@ -11,6 +11,6 @@ "main": "index.js",

"peerDependencies": {
"@angular/core": "2.0.0-rc.0",
"@angular/common": "2.0.0-rc.0",
"@angular/platform-browser": "2.0.0-rc.0"
"@angular/core": "2.0.0-rc.1",
"@angular/common": "2.0.0-rc.1",
"@angular/platform-browser": "2.0.0-rc.1"
}
}

@@ -0,1 +1,5 @@

/**
* Name of the default outlet outlet.
* @type {string}
*/
export declare const DEFAULT_OUTLET_NAME: string;
"use strict";
/**
* Name of the default outlet outlet.
* @type {string}
*/
exports.DEFAULT_OUTLET_NAME = "__DEFAULT";
//# sourceMappingURL=constants.js.map
import { OnDestroy } from '@angular/core';
import { Router } from '../router';
import { RouteSegment } from '../segments';
/**
* The RouterLink directive lets you link to specific parts of your app.
*
* Consider the following route configuration:
* ```
* @Routes([
* { path: '/user', component: UserCmp }
* ]);
* class MyComp {}
* ```
*
* When linking to this `User` route, you can write:
*
* ```
* <a [routerLink]="['/user']">link to user component</a>
* ```
*
* RouterLink expects the value to be an array of path segments, followed by the params
* for that level of routing. For instance `['/team', {teamId: 1}, 'user', {userId: 2}]`
* means that we want to generate a link to `/team;teamId=1/user;userId=2`.
*
* The first segment name can be prepended with `/`, `./`, or `../`.
* If the segment begins with `/`, the router will look up the route from the root of the app.
* If the segment begins with `./`, or doesn't begin with a slash, the router will
* instead look in the current component's children for the route.
* And if the segment begins with `../`, the router will go up one segment in the url.
*
* See {@link Router.createUrlTree} for more information.
*/
export declare class RouterLink implements OnDestroy {

@@ -8,11 +38,11 @@ private _routeSegment;

target: string;
private _changes;
private _commands;
private _subscription;
private href;
private isActive;
href: string;
isActive: boolean;
constructor(_routeSegment: RouteSegment, _router: Router);
ngOnDestroy(): void;
routerLink: any[];
routerLink: any[] | any;
onClick(): boolean;
private _updateTargetUrlAndHref();
}

@@ -12,4 +12,6 @@ "use strict";

this._router = _router;
this._changes = [];
this._commands = [];
this.isActive = false;
// because auxiliary links take existing primary and auxiliary routes into account,
// we need to update the link whenever params or other routes change.
this._subscription =

@@ -21,3 +23,8 @@ async_1.ObservableWrapper.subscribe(_router.changes, function (_) { _this._updateTargetUrlAndHref(); });

set: function (data) {
this._changes = data;
if (lang_1.isArray(data)) {
this._commands = data;
}
else {
this._commands = [data];
}
this._updateTargetUrlAndHref();

@@ -29,4 +36,5 @@ },

RouterLink.prototype.onClick = function () {
// If no target, or if target is _self, prevent default browser behavior
if (!lang_1.isString(this.target) || this.target == '_self') {
this._router.navigate(this._changes, this._routeSegment);
this._router.navigate(this._commands, this._routeSegment);
return false;

@@ -37,3 +45,3 @@ }

RouterLink.prototype._updateTargetUrlAndHref = function () {
var tree = this._router.createUrlTree(this._changes, this._routeSegment);
var tree = this._router.createUrlTree(this._commands, this._routeSegment);
if (lang_1.isPresent(tree)) {

@@ -40,0 +48,0 @@ this.href = this._router.serializeUrl(tree);

import { ResolvedReflectiveProvider, ViewContainerRef, ComponentRef, ComponentFactory } from '@angular/core';
import { RouterOutletMap } from '../router';
/**
* A router outlet is a placeholder that Angular dynamically fills based on the application's route.
*
* ## Use
*
* ```
* <router-outlet></router-outlet>
* ```
*
* Outlets can be named.
*
* ```
* <router-outlet name="right"></router-outlet>
* ```
*/
export declare class RouterOutlet {

@@ -9,5 +24,14 @@ private _location;

unload(): void;
/**
* Returns the loaded component.
*/
loadedComponent: Object;
/**
* Returns true is the outlet is not empty.
*/
isLoaded: boolean;
/**
* Called by the Router to instantiate a new component.
*/
load(factory: ComponentFactory<any>, providers: ResolvedReflectiveProvider[], outletMap: RouterOutletMap): ComponentRef<any>;
}

@@ -16,2 +16,5 @@ "use strict";

Object.defineProperty(RouterOutlet.prototype, "loadedComponent", {
/**
* Returns the loaded component.
*/
get: function () { return lang_1.isPresent(this._loaded) ? this._loaded.instance : null; },

@@ -22,2 +25,5 @@ enumerable: true,

Object.defineProperty(RouterOutlet.prototype, "isLoaded", {
/**
* Returns true is the outlet is not empty.
*/
get: function () { return lang_1.isPresent(this._loaded); },

@@ -27,2 +33,5 @@ enumerable: true,

});
/**
* Called by the Router to instantiate a new component.
*/
RouterOutlet.prototype.load = function (factory, providers, outletMap) {

@@ -29,0 +38,0 @@ this.outletMap = outletMap;

import { RouteSegment, RouteTree } from './segments';
/**
* Defines route lifecycle method `routerOnActivate`, which is called by the router at the end of a
* successful route navigation.
*
* The `routerOnActivate` hook is called with the current and previous {@link RouteSegment}s of the
* component and with the corresponding route trees.
*/
export interface OnActivate {
routerOnActivate(curr: RouteSegment, prev?: RouteSegment, currTree?: RouteTree, prevTree?: RouteTree): void;
}
/**
* Defines route lifecycle method `routerOnDeactivate`, which is called by the router before
* destroying a component as part of a route change.
*
* The `routerOnDeactivate` hook is called with two {@link RouteTree}s, representing the current
* and the future state of the application.
*
* `routerOnDeactivate` must return a promise. The route change will wait until the promise settles.
*/
export interface CanDeactivate {
routerCanDeactivate(currTree?: RouteTree, futureTree?: RouteTree): Promise<boolean>;
}
import { RouteSegment, UrlTree, RouteTree } from './segments';
export declare function link(segment: RouteSegment, routeTree: RouteTree, urlTree: UrlTree, change: any[]): UrlTree;
export declare function link(segment: RouteSegment, routeTree: RouteTree, urlTree: UrlTree, commands: any[]): UrlTree;
"use strict";
var segments_1 = require('./segments');
var lang_1 = require('./facade/lang');
var exceptions_1 = require('./facade/exceptions');
var collection_1 = require('./facade/collection');
function link(segment, routeTree, urlTree, change) {
if (change.length === 0)
// TODO: vsavkin: should reuse segments
function link(segment, routeTree, urlTree, commands) {
if (commands.length === 0)
return urlTree;
var startingNode;
var normalizedChange;
if (lang_1.isString(change[0]) && change[0].startsWith("./")) {
normalizedChange = ["/", change[0].substring(2)].concat(change.slice(1));
startingNode = _findStartingNode(_findUrlSegment(segment, routeTree), segments_1.rootNode(urlTree));
var normalizedCommands = _normalizeCommands(commands);
if (_navigateToRoot(normalizedCommands)) {
return new segments_1.UrlTree(new segments_1.TreeNode(urlTree.root, []));
}
else if (lang_1.isString(change[0]) && change.length === 1 && change[0] == "/") {
normalizedChange = change;
startingNode = segments_1.rootNode(urlTree);
var startingNode = _findStartingNode(normalizedCommands, urlTree, segment, routeTree);
var updated = normalizedCommands.commands.length > 0 ?
_updateMany(collection_1.ListWrapper.clone(startingNode.children), normalizedCommands.commands) : [];
var newRoot = _constructNewTree(segments_1.rootNode(urlTree), startingNode, updated);
return new segments_1.UrlTree(newRoot);
}
exports.link = link;
function _navigateToRoot(normalizedChange) {
return normalizedChange.isAbsolute && normalizedChange.commands.length === 1 && normalizedChange.commands[0] == "/";
}
var _NormalizedNavigationCommands = (function () {
function _NormalizedNavigationCommands(isAbsolute, numberOfDoubleDots, commands) {
this.isAbsolute = isAbsolute;
this.numberOfDoubleDots = numberOfDoubleDots;
this.commands = commands;
}
else if (lang_1.isString(change[0]) && !change[0].startsWith("/")) {
normalizedChange = ["/"].concat(change);
startingNode = _findStartingNode(_findUrlSegment(segment, routeTree), segments_1.rootNode(urlTree));
return _NormalizedNavigationCommands;
}());
function _normalizeCommands(commands) {
;
'';
if (lang_1.isString(commands[0]) && commands.length === 1 && commands[0] == "/") {
return new _NormalizedNavigationCommands(true, 0, commands);
}
else {
normalizedChange = ["/"].concat(change);
startingNode = segments_1.rootNode(urlTree);
var numberOfDoubleDots = 0;
var isAbsolute = false;
var res = [];
for (var i = 0; i < commands.length; ++i) {
var c = commands[i];
if (!lang_1.isString(c)) {
res.push(c);
continue;
}
var parts = c.split('/');
for (var j = 0; j < parts.length; ++j) {
var cc = parts[j];
// first exp is treated in a special way
if (i == 0) {
if (j == 0 && cc == ".") {
}
else if (j == 0 && cc == "") {
isAbsolute = true;
}
else if (cc == "..") {
numberOfDoubleDots++;
}
else if (cc != '') {
res.push(cc);
}
}
else {
if (cc != '') {
res.push(cc);
}
}
}
}
var updated = _update(startingNode, normalizedChange);
var newRoot = _constructNewTree(segments_1.rootNode(urlTree), startingNode, updated);
return new segments_1.UrlTree(newRoot);
return new _NormalizedNavigationCommands(isAbsolute, numberOfDoubleDots, res);
}
exports.link = link;
function _findUrlSegment(segment, routeTree) {
function _findUrlSegment(segment, routeTree, urlTree, numberOfDoubleDots) {
var s = segment;
var res = null;
while (lang_1.isBlank(res)) {
res = collection_1.ListWrapper.last(s.urlSegments);
while (s.urlSegments.length === 0) {
s = routeTree.parent(s);
}
return res;
var urlSegment = collection_1.ListWrapper.last(s.urlSegments);
var path = urlTree.pathFromRoot(urlSegment);
if (path.length <= numberOfDoubleDots) {
throw new exceptions_1.BaseException("Invalid number of '../'");
}
return path[path.length - 1 - numberOfDoubleDots];
}
function _findStartingNode(segment, node) {
function _findStartingNode(normalizedChange, urlTree, segment, routeTree) {
if (normalizedChange.isAbsolute) {
return segments_1.rootNode(urlTree);
}
else {
var urlSegment = _findUrlSegment(segment, routeTree, urlTree, normalizedChange.numberOfDoubleDots);
return _findMatchingNode(urlSegment, segments_1.rootNode(urlTree));
}
}
function _findMatchingNode(segment, node) {
if (node.value === segment)

@@ -45,3 +99,3 @@ return node;

var c = _a[_i];
var r = _findStartingNode(segment, c);
var r = _findMatchingNode(segment, c);
if (lang_1.isPresent(r))

@@ -54,3 +108,3 @@ return r;

if (node === original) {
return new segments_1.TreeNode(node.value, updated.children);
return new segments_1.TreeNode(node.value, updated);
}

@@ -61,50 +115,63 @@ else {

}
function _update(node, changes) {
var rest = changes.slice(1);
var outlet = _outlet(changes);
var segment = _segment(changes);
if (lang_1.isString(segment) && segment[0] == "/")
segment = segment.substring(1);
function _update(node, commands) {
var rest = commands.slice(1);
var next = rest.length === 0 ? null : rest[0];
var outlet = _outlet(commands);
var segment = _segment(commands);
// reach the end of the tree => create new tree nodes.
if (lang_1.isBlank(node)) {
var urlSegment = new segments_1.UrlSegment(segment, null, outlet);
if (lang_1.isBlank(node) && !lang_1.isStringMap(next)) {
var urlSegment = new segments_1.UrlSegment(segment, {}, outlet);
var children = rest.length === 0 ? [] : [_update(null, rest)];
return new segments_1.TreeNode(urlSegment, children);
}
else if (lang_1.isBlank(node) && lang_1.isStringMap(next)) {
var urlSegment = new segments_1.UrlSegment(segment, next, outlet);
return _recurse(urlSegment, node, rest.slice(1));
}
else if (outlet != node.value.outlet) {
return node;
}
else if (lang_1.isStringMap(segment)) {
var newSegment = new segments_1.UrlSegment(node.value.segment, segment, node.value.outlet);
return _recurse(newSegment, node, rest);
}
else if (lang_1.isStringMap(next)) {
var urlSegment = new segments_1.UrlSegment(segment, next, outlet);
return _recurse(urlSegment, node, rest.slice(1));
}
else {
var urlSegment = lang_1.isStringMap(segment) ? new segments_1.UrlSegment(null, segment, null) :
new segments_1.UrlSegment(segment, null, outlet);
if (rest.length === 0) {
return new segments_1.TreeNode(urlSegment, []);
}
return new segments_1.TreeNode(urlSegment, _updateMany(collection_1.ListWrapper.clone(node.children), rest));
var urlSegment = new segments_1.UrlSegment(segment, {}, outlet);
return _recurse(urlSegment, node, rest);
}
}
function _updateMany(nodes, changes) {
var outlet = _outlet(changes);
function _recurse(urlSegment, node, rest) {
if (rest.length === 0) {
return new segments_1.TreeNode(urlSegment, []);
}
return new segments_1.TreeNode(urlSegment, _updateMany(collection_1.ListWrapper.clone(node.children), rest));
}
function _updateMany(nodes, commands) {
var outlet = _outlet(commands);
var nodesInRightOutlet = nodes.filter(function (c) { return c.value.outlet == outlet; });
if (nodesInRightOutlet.length > 0) {
var nodeRightOutlet = nodesInRightOutlet[0]; // there can be only one
nodes[nodes.indexOf(nodeRightOutlet)] = _update(nodeRightOutlet, changes);
nodes[nodes.indexOf(nodeRightOutlet)] = _update(nodeRightOutlet, commands);
}
else {
nodes.push(_update(null, changes));
nodes.push(_update(null, commands));
}
return nodes;
}
function _segment(changes) {
if (!lang_1.isString(changes[0]))
return changes[0];
var parts = changes[0].toString().split(":");
return parts.length > 1 ? parts[1] : changes[0];
function _segment(commands) {
if (!lang_1.isString(commands[0]))
return commands[0];
var parts = commands[0].toString().split(":");
return parts.length > 1 ? parts[1] : commands[0];
}
function _outlet(changes) {
if (!lang_1.isString(changes[0]))
function _outlet(commands) {
if (!lang_1.isString(commands[0]))
return null;
var parts = changes[0].toString().split(":");
var parts = commands[0].toString().split(":");
return parts.length > 1 ? parts[0] : null;
}
//# sourceMappingURL=link.js.map
import { RoutesMetadata, RouteMetadata } from "./metadata";
/**
* Defines routes for a given component.
*
* It takes an array of {@link RouteMetadata}s.
*/
export interface RoutesFactory {

@@ -6,2 +11,7 @@ (routes: RouteMetadata[]): any;

}
/**
* Defines routes for a given component.
*
* It takes an array of {@link RouteMetadata}s.
*/
export declare var Routes: RoutesFactory;
"use strict";
var metadata_1 = require("./metadata");
var core_private_1 = require('../core_private');
/**
* Defines routes for a given component.
*
* It takes an array of {@link RouteMetadata}s.
*/
exports.Routes = core_private_1.makeDecorator(metadata_1.RoutesMetadata);
//# sourceMappingURL=decorators.js.map
import { Type } from '@angular/core';
/**
* Information about a route.
*
* It has the following properties:
* - `path` is a string that uses the route matcher DSL.
* - `component` a component type.
*
* ### Example
* ```
* import {Routes} from '@angular/router';
*
* @Routes([
* {path: '/home', component: HomeCmp}
* ])
* class MyApp {}
* ```
*
* @ts2dart_const
*/
export declare abstract class RouteMetadata {

@@ -6,2 +25,6 @@ path: string;

}
/**
* See {@link RouteMetadata} for more information.
* @ts2dart_const
*/
export declare class Route implements RouteMetadata {

@@ -16,2 +39,8 @@ path: string;

}
/**
* Defines routes for a given component.
*
* It takes an array of {@link RouteMetadata}s.
* @ts2dart_const
*/
export declare class RoutesMetadata {

@@ -18,0 +47,0 @@ routes: RouteMetadata[];

"use strict";
var lang_1 = require("../facade/lang");
/**
* Information about a route.
*
* It has the following properties:
* - `path` is a string that uses the route matcher DSL.
* - `component` a component type.
*
* ### Example
* ```
* import {Routes} from '@angular/router';
*
* @Routes([
* {path: '/home', component: HomeCmp}
* ])
* class MyApp {}
* ```
*
* @ts2dart_const
*/
var RouteMetadata = (function () {

@@ -19,3 +38,6 @@ function RouteMetadata() {

exports.RouteMetadata = RouteMetadata;
/* @ts2dart_const */
/**
* See {@link RouteMetadata} for more information.
* @ts2dart_const
*/
var Route = (function () {

@@ -31,3 +53,8 @@ function Route(_a) {

exports.Route = Route;
/* @ts2dart_const */
/**
* Defines routes for a given component.
*
* It takes an array of {@link RouteMetadata}s.
* @ts2dart_const
*/
var RoutesMetadata = (function () {

@@ -34,0 +61,0 @@ function RoutesMetadata(routes) {

@@ -12,3 +12,3 @@ "use strict";

function recognize(componentResolver, type, url) {
var matched = new _MatchResult(type, [url.root], null, segments_1.rootNode(url).children, []);
var matched = new _MatchResult(type, [url.root], {}, segments_1.rootNode(url).children, []);
return _constructSegment(componentResolver, matched).then(function (roots) { return new segments_1.RouteTree(roots[0]); });

@@ -71,3 +71,3 @@ }

.then(function (factory) {
var segment = new segments_1.RouteSegment([], null, constants_1.DEFAULT_OUTLET_NAME, r[0].component, factory);
var segment = new segments_1.RouteSegment([], {}, constants_1.DEFAULT_OUTLET_NAME, r[0].component, factory);
return [new segments_1.TreeNode(segment, children)];

@@ -122,8 +122,4 @@ });

}
if (lang_1.isPresent(current) && lang_1.isBlank(current.value.segment)) {
lastParent = lastSegment;
lastSegment = current;
}
var p = lastSegment.value.parameters;
var parameters = collection_1.StringMapWrapper.merge(lang_1.isBlank(p) ? {} : p, positionalParams);
var parameters = collection_1.StringMapWrapper.merge(p, positionalParams);
var axuUrlSubtrees = lang_1.isPresent(lastParent) ? lastParent.children.slice(1) : [];

@@ -130,0 +126,0 @@ return new _MatchResult(route.component, consumedUrlSegments, parameters, lastSegment.children, axuUrlSubtrees);

@@ -0,1 +1,4 @@

/**
* The Platform agnostic ROUTER PROVIDERS
*/
export declare const ROUTER_PROVIDERS_COMMON: any[];

@@ -8,2 +8,5 @@ "use strict";

var core_3 = require('@angular/core');
/**
* The Platform agnostic ROUTER PROVIDERS
*/
exports.ROUTER_PROVIDERS_COMMON = [

@@ -10,0 +13,0 @@ router_1.RouterOutletMap,

@@ -0,1 +1,23 @@

/**
* A list of {@link Provider}s. To use the router, you must add this to your application.
*
* ```
* import {Component} from '@angular/core';
* import {
* ROUTER_DIRECTIVES,
* ROUTER_PROVIDERS,
* Routes
* } from '@angular/router';
*
* @Component({directives: [ROUTER_DIRECTIVES]})
* @Routes([
* {...},
* ])
* class AppCmp {
* // ...
* }
*
* bootstrap(AppCmp, [ROUTER_PROVIDERS]);
* ```
*/
export declare const ROUTER_PROVIDERS: any[];

@@ -5,2 +5,24 @@ "use strict";

var common_1 = require('@angular/common');
/**
* A list of {@link Provider}s. To use the router, you must add this to your application.
*
* ```
* import {Component} from '@angular/core';
* import {
* ROUTER_DIRECTIVES,
* ROUTER_PROVIDERS,
* Routes
* } from '@angular/router';
*
* @Component({directives: [ROUTER_DIRECTIVES]})
* @Routes([
* {...},
* ])
* class AppCmp {
* // ...
* }
*
* bootstrap(AppCmp, [ROUTER_PROVIDERS]);
* ```
*/
exports.ROUTER_PROVIDERS = [

@@ -7,0 +29,0 @@ router_providers_common_1.ROUTER_PROVIDERS_COMMON,

import { UrlTree } from './segments';
/**
* Defines a way to serialize/deserialize a url tree.
*/
export declare abstract class RouterUrlSerializer {
/**
* Parse a url into a {@Link UrlTree}
*/
abstract parse(url: string): UrlTree;
/**
* Converts a {@Link UrlTree} into a url
*/
abstract serialize(tree: UrlTree): string;
}
/**
* A default implementation of the serialization.
*/
export declare class DefaultRouterUrlSerializer extends RouterUrlSerializer {

@@ -7,0 +19,0 @@ parse(url: string): UrlTree;

@@ -10,2 +10,5 @@ "use strict";

var lang_1 = require('./facade/lang');
/**
* Defines a way to serialize/deserialize a url tree.
*/
var RouterUrlSerializer = (function () {

@@ -17,2 +20,5 @@ function RouterUrlSerializer() {

exports.RouterUrlSerializer = RouterUrlSerializer;
/**
* A default implementation of the serialization.
*/
var DefaultRouterUrlSerializer = (function (_super) {

@@ -43,4 +49,3 @@ __extends(DefaultRouterUrlSerializer, _super);

if (node.children.length > 0) {
var slash = lang_1.isBlank(node.children[0].value.segment) ? "" : "/";
return "" + slash + _serializeUrlTreeNodes(node.children);
return "/" + _serializeUrlTreeNodes(node.children);
}

@@ -74,3 +79,3 @@ else {

if (url == '' || url == '/') {
return new segments_1.TreeNode(new segments_1.UrlSegment('', null, null), []);
return new segments_1.TreeNode(new segments_1.UrlSegment('', {}, null), []);
}

@@ -83,4 +88,3 @@ else {

var segments = this.parseSegments();
var queryParams = this.peekStartsWith('?') ? this.parseQueryParams() : null;
return new segments_1.TreeNode(new segments_1.UrlSegment('', queryParams, null), segments);
return new segments_1.TreeNode(new segments_1.UrlSegment('', {}, null), segments);
};

@@ -102,3 +106,3 @@ _UrlParser.prototype.parseSegments = function (outletName) {

}
var matrixParams = null;
var matrixParams = {};
if (this.peekStartsWith(';')) {

@@ -116,13 +120,5 @@ matrixParams = this.parseMatrixParams();

}
if (lang_1.isPresent(matrixParams)) {
var matrixParamsSegment = new segments_1.UrlSegment(null, matrixParams, null);
var matrixParamsNode = new segments_1.TreeNode(matrixParamsSegment, children);
var segment = new segments_1.UrlSegment(path, null, outletName);
return [new segments_1.TreeNode(segment, [matrixParamsNode].concat(aux))];
}
else {
var segment = new segments_1.UrlSegment(path, null, outletName);
var node = new segments_1.TreeNode(segment, children);
return [node].concat(aux);
}
var segment = new segments_1.UrlSegment(path, matrixParams, outletName);
var node = new segments_1.TreeNode(segment, children);
return [node].concat(aux);
};

@@ -129,0 +125,0 @@ _UrlParser.prototype.parseQueryParams = function () {

@@ -8,2 +8,5 @@ import { ComponentResolver } from '@angular/core';

import { RouteSegment, UrlTree, RouteTree } from './segments';
/**
* @internal
*/
export declare class RouterOutletMap {

@@ -16,2 +19,8 @@ /** @internal */

}
/**
* The `Router` is responsible for mapping URLs to components.
*
* You can see the state of the router by inspecting the read-only fields `router.urlTree`
* and `router.routeTree`.
*/
export declare class Router {

@@ -28,14 +37,82 @@ private _rootComponent;

private _changes;
/**
* @internal
*/
constructor(_rootComponent: Object, _rootComponentType: Type, _componentResolver: ComponentResolver, _urlSerializer: RouterUrlSerializer, _routerOutletMap: RouterOutletMap, _location: Location);
/**
* Returns the current url tree.
*/
urlTree: UrlTree;
/**
* Returns the current route tree.
*/
routeTree: RouteTree;
/**
* An observable or url changes from the router.
*/
changes: Observable<void>;
/**
* Navigate based on the provided url. This navigation is always absolute.
*
* ### Usage
*
* ```
* router.navigateByUrl("/team/33/user/11");
* ```
*/
navigateByUrl(url: string): Promise<void>;
navigate(changes: any[], segment?: RouteSegment): Promise<void>;
/**
* Navigate based on the provided array of commands and a starting point.
* If no segment is provided, the navigation is absolute.
*
* ### Usage
*
* ```
* router.navigate(['team', 33, 'team', '11], segment);
* ```
*/
navigate(commands: any[], segment?: RouteSegment): Promise<void>;
/**
* @internal
*/
dispose(): void;
/**
* Applies an array of commands to the current url tree and creates
* a new url tree.
*
* When given a segment, applies the given commands starting from the segment.
* When not given a segment, applies the given command starting from the root.
*
* ### Usage
*
* ```
* // create /team/33/user/11
* router.createUrlTree(['/team', 33, 'user', 11]);
*
* // create /team/33;expand=true/user/11
* router.createUrlTree(['/team', 33, {expand: true}, 'user', 11]);
*
* // you can collapse static fragments like this
* router.createUrlTree(['/team/33/user', userId]);
*
* // assuming the current url is `/team/33/user/11` and the segment points to `user/11`
*
* // navigate to /team/33/user/11/details
* router.createUrlTree(['details'], segment);
*
* // navigate to /team/33/user/22
* router.createUrlTree(['../22'], segment);
*
* // navigate to /team/44/user/22
* router.createUrlTree(['../../team/44/user/22'], segment);
* ```
*/
createUrlTree(commands: any[], segment?: RouteSegment): UrlTree;
/**
* Serializes a {@link UrlTree} into a string.
*/
serializeUrl(url: UrlTree): string;
private _createInitialTree();
private _setUpLocationChangeListener();
private _navigate(url);
createUrlTree(changes: any[], segment?: RouteSegment): UrlTree;
serializeUrl(url: UrlTree): string;
changes: Observable<void>;
routeTree: RouteTree;
}

@@ -13,2 +13,5 @@ "use strict";

var constants_1 = require('./constants');
/**
* @internal
*/
var RouterOutletMap = (function () {

@@ -23,3 +26,12 @@ function RouterOutletMap() {

exports.RouterOutletMap = RouterOutletMap;
/**
* The `Router` is responsible for mapping URLs to components.
*
* You can see the state of the router by inspecting the read-only fields `router.urlTree`
* and `router.routeTree`.
*/
var Router = (function () {
/**
* @internal
*/
function Router(_rootComponent, _rootComponentType, _componentResolver, _urlSerializer, _routerOutletMap, _location) {

@@ -38,2 +50,5 @@ this._rootComponent = _rootComponent;

Object.defineProperty(Router.prototype, "urlTree", {
/**
* Returns the current url tree.
*/
get: function () { return this._urlTree; },

@@ -43,11 +58,88 @@ enumerable: true,

});
Object.defineProperty(Router.prototype, "routeTree", {
/**
* Returns the current route tree.
*/
get: function () { return this._prevTree; },
enumerable: true,
configurable: true
});
Object.defineProperty(Router.prototype, "changes", {
/**
* An observable or url changes from the router.
*/
get: function () { return this._changes; },
enumerable: true,
configurable: true
});
/**
* Navigate based on the provided url. This navigation is always absolute.
*
* ### Usage
*
* ```
* router.navigateByUrl("/team/33/user/11");
* ```
*/
Router.prototype.navigateByUrl = function (url) {
return this._navigate(this._urlSerializer.parse(url));
};
Router.prototype.navigate = function (changes, segment) {
return this._navigate(this.createUrlTree(changes, segment));
/**
* Navigate based on the provided array of commands and a starting point.
* If no segment is provided, the navigation is absolute.
*
* ### Usage
*
* ```
* router.navigate(['team', 33, 'team', '11], segment);
* ```
*/
Router.prototype.navigate = function (commands, segment) {
return this._navigate(this.createUrlTree(commands, segment));
};
/**
* @internal
*/
Router.prototype.dispose = function () { async_1.ObservableWrapper.dispose(this._locationSubscription); };
/**
* Applies an array of commands to the current url tree and creates
* a new url tree.
*
* When given a segment, applies the given commands starting from the segment.
* When not given a segment, applies the given command starting from the root.
*
* ### Usage
*
* ```
* // create /team/33/user/11
* router.createUrlTree(['/team', 33, 'user', 11]);
*
* // create /team/33;expand=true/user/11
* router.createUrlTree(['/team', 33, {expand: true}, 'user', 11]);
*
* // you can collapse static fragments like this
* router.createUrlTree(['/team/33/user', userId]);
*
* // assuming the current url is `/team/33/user/11` and the segment points to `user/11`
*
* // navigate to /team/33/user/11/details
* router.createUrlTree(['details'], segment);
*
* // navigate to /team/33/user/22
* router.createUrlTree(['../22'], segment);
*
* // navigate to /team/44/user/22
* router.createUrlTree(['../../team/44/user/22'], segment);
* ```
*/
Router.prototype.createUrlTree = function (commands, segment) {
var s = lang_1.isPresent(segment) ? segment : this._prevTree.root;
return link_1.link(s, this._prevTree, this.urlTree, commands);
};
/**
* Serializes a {@link UrlTree} into a string.
*/
Router.prototype.serializeUrl = function (url) { return this._urlSerializer.serialize(url); };
Router.prototype._createInitialTree = function () {
var root = new segments_1.RouteSegment([new segments_1.UrlSegment("", null, null)], null, constants_1.DEFAULT_OUTLET_NAME, this._rootComponentType, null);
var root = new segments_1.RouteSegment([new segments_1.UrlSegment("", {}, null)], {}, constants_1.DEFAULT_OUTLET_NAME, this._rootComponentType, null);
return new segments_1.RouteTree(new segments_1.TreeNode(root, []));

@@ -75,22 +167,2 @@ };

};
Router.prototype.createUrlTree = function (changes, segment) {
if (lang_1.isPresent(this._prevTree)) {
var s = lang_1.isPresent(segment) ? segment : this._prevTree.root;
return link_1.link(s, this._prevTree, this.urlTree, changes);
}
else {
return null;
}
};
Router.prototype.serializeUrl = function (url) { return this._urlSerializer.serialize(url); };
Object.defineProperty(Router.prototype, "changes", {
get: function () { return this._changes; },
enumerable: true,
configurable: true
});
Object.defineProperty(Router.prototype, "routeTree", {
get: function () { return this._prevTree; },
enumerable: true,
configurable: true
});
return Router;

@@ -97,0 +169,0 @@ }());

@@ -28,7 +28,7 @@ import { ComponentFactory, Type } from '@angular/core';

parameters: {
[key: string]: string;
[key: string]: any;
};
outlet: string;
constructor(segment: any, parameters: {
[key: string]: string;
[key: string]: any;
}, outlet: string);

@@ -40,3 +40,3 @@ toString(): string;

parameters: {
[key: string]: string;
[key: string]: any;
};

@@ -49,3 +49,3 @@ outlet: string;

constructor(urlSegments: UrlSegment[], parameters: {
[key: string]: string;
[key: string]: any;
}, outlet: string, type: Type, componentFactory: ComponentFactory<any>);

@@ -52,0 +52,0 @@ getParam(param: string): string;

@@ -122,4 +122,3 @@ "use strict";

var outletPrefix = lang_1.isBlank(this.outlet) ? "" : this.outlet + ":";
var segmentPrefix = lang_1.isBlank(this.segment) ? "" : this.segment;
return "" + outletPrefix + segmentPrefix + _serializeParams(this.parameters);
return "" + outletPrefix + this.segment + _serializeParams(this.parameters);
};

@@ -131,5 +130,3 @@ return UrlSegment;

var res = "";
if (lang_1.isPresent(params)) {
collection_1.StringMapWrapper.forEach(params, function (v, k) { return res += ";" + k + "=" + v; });
}
collection_1.StringMapWrapper.forEach(params, function (v, k) { return res += ";" + k + "=" + v; });
return res;

@@ -179,8 +176,2 @@ }

return false;
if (lang_1.isBlank(a.parameters) && !lang_1.isBlank(b.parameters))
return false;
if (!lang_1.isBlank(a.parameters) && lang_1.isBlank(b.parameters))
return false;
if (lang_1.isBlank(a.parameters) && lang_1.isBlank(b.parameters))
return true;
return collection_1.StringMapWrapper.equals(a.parameters, b.parameters);

@@ -198,8 +189,8 @@ }

return false;
if (lang_1.isBlank(a.parameters) && !lang_1.isBlank(b.parameters))
return false;
if (!lang_1.isBlank(a.parameters) && lang_1.isBlank(b.parameters))
return false;
if (lang_1.isBlank(a.parameters) && lang_1.isBlank(b.parameters))
return true;
if (lang_1.isBlank(a.parameters)) {
console.log("a", a);
}
if (lang_1.isBlank(b.parameters)) {
console.log("b", b);
}
return collection_1.StringMapWrapper.equals(a.parameters, b.parameters);

@@ -206,0 +197,0 @@ }

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc