Permalink
Browse files

add info about replaceHash() on README

  • Loading branch information...
1 parent 2bcdf67 commit 8c4e630f0ea2b2f9b33f019354eecbfcc847ff7b @millermedeiros committed May 5, 2012
Showing with 22 additions and 0 deletions.
  1. +22 −0 README.md
View
@@ -98,6 +98,28 @@ setHashSilently('lorem/ipsum'); //set hash value without dispatching changed eve
hasher.setHash('bar');
```
+
+### Setting hash value without generating a new history record
+
+Hasher also contains the method `replaceHash()`. It works very similarly to the
+`setHash()` method (will also dispatch a `changed` signal), the main difference
+it that it won't keep the **previous** hash on the history record (similar to
+`location.replace()`). It's useful for redirections and any other change that
+shouldn't be on the browser history.
+
+```js
+function onHasherInit(curHash){
+ if (curHash == '') {
+ // redirect to "home" hash without keeping the empty hash on the history
+ hasher.replaceHash('home');
+ }
+}
+hasher.initialized.add(onHasherInit);
+hasher.changed.add(console.log, console); // log all hashes
+hasher.init();
+```
+
+
### Routes: Using Hasher together with Crossroads.js ###
Hasher is only focused on providing a reliable and clear API for setting hash values and

0 comments on commit 8c4e630

Please sign in to comment.