fix(router): use StringWrapper.startsWith

This commit is contained in:
Brian Ford 2015-09-21 12:05:34 -07:00
parent 43f97a951c
commit 6e0ca7f39a
2 changed files with 13 additions and 6 deletions

View File

@ -52,7 +52,8 @@ export class RouteRecognizer {
if (config instanceof AuxRoute) {
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);
this.auxRoutes.set(path, recognizer);
return recognizer.terminal;
@ -140,11 +141,11 @@ export class Redirector {
toSegments: string[] = [];
constructor(path: string, redirectTo: string) {
if (path.startsWith('/')) {
if (StringWrapper.startsWith(path, '/')) {
path = path.substring(1);
}
this.segments = path.split('/');
if (redirectTo.startsWith('/')) {
if (StringWrapper.startsWith(redirectTo, '/')) {
redirectTo = redirectTo.substring(1);
}
this.toSegments = redirectTo.split('/');

View File

@ -1,5 +1,11 @@
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';
/**
@ -71,10 +77,10 @@ function matchUrlSegment(str: string): string {
export class UrlParser {
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 {
if (!this._remaining.startsWith(str)) {
if (!StringWrapper.startsWith(this._remaining, str)) {
throw new BaseException(`Expected "${str}".`);
}
this._remaining = this._remaining.substring(str.length);