feat(router): allow configuring app base href via token

This commit is contained in:
Brian Ford
2015-06-15 15:41:09 -07:00
parent 0c282e826a
commit cab1d0ef0f
5 changed files with 134 additions and 65 deletions

View File

@ -1,16 +1,19 @@
import {BrowserLocation} from './browser_location';
import {StringWrapper} from 'angular2/src/facade/lang';
import {StringWrapper, isPresent, CONST_EXPR} from 'angular2/src/facade/lang';
import {EventEmitter, ObservableWrapper} from 'angular2/src/facade/async';
import {Injectable} from 'angular2/di';
import {OpaqueToken, Injectable, Optional, Inject} from 'angular2/di';
export const appBaseHrefToken: OpaqueToken = CONST_EXPR(new OpaqueToken('locationHrefToken'));
@Injectable()
export class Location {
private _subject: EventEmitter;
private _baseHref: string;
constructor(public _browserLocation: BrowserLocation) {
constructor(public _browserLocation: BrowserLocation,
@Optional() @Inject(appBaseHrefToken) href?: string) {
this._subject = new EventEmitter();
this._baseHref = stripIndexHtml(this._browserLocation.getBaseHref());
this._baseHref = stripIndexHtml(isPresent(href) ? href : this._browserLocation.getBaseHref());
this._browserLocation.onPopState((_) => this._onPopState(_));
}