fix(router): use StringWrapper.startsWith
This commit is contained in:
parent
43f97a951c
commit
6e0ca7f39a
|
@ -52,7 +52,8 @@ export class RouteRecognizer {
|
||||||
|
|
||||||
if (config instanceof AuxRoute) {
|
if (config instanceof AuxRoute) {
|
||||||
handler = new SyncRouteHandler(config.component, config.data);
|
handler = new SyncRouteHandler(config.component, config.data);
|
||||||
let path = config.path.startsWith('/') ? config.path.substring(1) : config.path;
|
let path =
|
||||||
|
StringWrapper.startsWith(config.path, '/') ? config.path.substring(1) : config.path;
|
||||||
var recognizer = new PathRecognizer(config.path, handler);
|
var recognizer = new PathRecognizer(config.path, handler);
|
||||||
this.auxRoutes.set(path, recognizer);
|
this.auxRoutes.set(path, recognizer);
|
||||||
return recognizer.terminal;
|
return recognizer.terminal;
|
||||||
|
@ -140,11 +141,11 @@ export class Redirector {
|
||||||
toSegments: string[] = [];
|
toSegments: string[] = [];
|
||||||
|
|
||||||
constructor(path: string, redirectTo: string) {
|
constructor(path: string, redirectTo: string) {
|
||||||
if (path.startsWith('/')) {
|
if (StringWrapper.startsWith(path, '/')) {
|
||||||
path = path.substring(1);
|
path = path.substring(1);
|
||||||
}
|
}
|
||||||
this.segments = path.split('/');
|
this.segments = path.split('/');
|
||||||
if (redirectTo.startsWith('/')) {
|
if (StringWrapper.startsWith(redirectTo, '/')) {
|
||||||
redirectTo = redirectTo.substring(1);
|
redirectTo = redirectTo.substring(1);
|
||||||
}
|
}
|
||||||
this.toSegments = redirectTo.split('/');
|
this.toSegments = redirectTo.split('/');
|
||||||
|
|
|
@ -1,5 +1,11 @@
|
||||||
import {StringMap, StringMapWrapper} from 'angular2/src/core/facade/collection';
|
import {StringMap, StringMapWrapper} from 'angular2/src/core/facade/collection';
|
||||||
import {isPresent, isBlank, RegExpWrapper, CONST_EXPR} from 'angular2/src/core/facade/lang';
|
import {
|
||||||
|
isPresent,
|
||||||
|
isBlank,
|
||||||
|
StringWrapper,
|
||||||
|
RegExpWrapper,
|
||||||
|
CONST_EXPR
|
||||||
|
} from 'angular2/src/core/facade/lang';
|
||||||
import {BaseException, WrappedException} from 'angular2/src/core/facade/exceptions';
|
import {BaseException, WrappedException} from 'angular2/src/core/facade/exceptions';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -71,10 +77,10 @@ function matchUrlSegment(str: string): string {
|
||||||
export class UrlParser {
|
export class UrlParser {
|
||||||
private _remaining: string;
|
private _remaining: string;
|
||||||
|
|
||||||
peekStartsWith(str: string): boolean { return this._remaining.startsWith(str); }
|
peekStartsWith(str: string): boolean { return StringWrapper.startsWith(this._remaining, str); }
|
||||||
|
|
||||||
capture(str: string): void {
|
capture(str: string): void {
|
||||||
if (!this._remaining.startsWith(str)) {
|
if (!StringWrapper.startsWith(this._remaining, str)) {
|
||||||
throw new BaseException(`Expected "${str}".`);
|
throw new BaseException(`Expected "${str}".`);
|
||||||
}
|
}
|
||||||
this._remaining = this._remaining.substring(str.length);
|
this._remaining = this._remaining.substring(str.length);
|
||||||
|
|
Loading…
Reference in New Issue