feat(router): add support for hash-based location

Closes #2555
This commit is contained in:
Brian Ford 2015-06-15 14:34:14 -07:00
parent 0a51ccbd68
commit a67f2314f9
2 changed files with 33 additions and 0 deletions

View File

@ -12,6 +12,7 @@ export {RouterLink} from './src/router/router_link';
export {RouteParams} from './src/router/instruction';
export {RouteRegistry} from './src/router/route_registry';
export {LocationStrategy} from './src/router/location_strategy';
export {HashLocationStrategy} from './src/router/hash_location_strategy';
export {HTML5LocationStrategy} from './src/router/html5_location_strategy';
export {Location, appBaseHrefToken} from './src/router/location';
export {Pipeline} from './src/router/pipeline';

View File

@ -0,0 +1,32 @@
import {DOM} from 'angular2/src/dom/dom_adapter';
import {Injectable} from 'angular2/di';
import {LocationStrategy} from './location_strategy';
import {EventListener, History, Location} from 'angular2/src/facade/browser';
@Injectable()
export class HashLocationStrategy extends LocationStrategy {
private _location: Location;
private _history: History;
constructor() {
super();
this._location = DOM.getLocation();
this._history = DOM.getHistory();
}
onPopState(fn: EventListener): void {
DOM.getGlobalEventTarget('window').addEventListener('popstate', fn, false);
}
getBaseHref(): string { return ''; }
path(): string { return this._location.hash; }
pushState(state: any, title: string, url: string) {
this._history.pushState(state, title, '#' + url);
}
forward(): void { this._history.forward(); }
back(): void { this._history.back(); }
}