-
Notifications
You must be signed in to change notification settings - Fork 25.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(router): add support for hash-based location
Closes #2555
- Loading branch information
Showing
2 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); } | ||
} |
a67f231
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@btford how do I enable hash based location?
a67f231
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm also interested; I didn't dare to ask given how fresh the commit was.. :D
a67f231
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rolandjitsu @dsebastien
a67f231
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tuurbo
How can I import
bind
function?I used to use
import {bind} from "angular2/angular2"
in 2.0.0-alpha.31, but as now 2.0.0-alpha.35, bind is undefineda67f231
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gutenye As of alpha 35
import {bind} from 'angular2/di';
works for me.https://gitter.im/angular/angular is a good place to ask questions if your looking for more help