Skip to content

Commit

Permalink
fix leeluolee#19: _fixInitState using hash mode should set initial hash
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecasar committed Oct 16, 2015
1 parent a1fa7db commit 12e4a73
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 27 deletions.
23 changes: 10 additions & 13 deletions src/histery.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,19 +177,16 @@ _.extend( _.emitable(Histery), {
// or we use hash in html5supoort mode (when paste url in other url)
// then , histery should repara it
_fixInitState: function(){
var pathname = _.cleanPath(this.location.pathname), hash, hashInPathName;

// dont support history popstate but config the html5 mode
if( this.mode !== HISTORY && this.html5){

hashInPathName = pathname.replace(this.rRoot, "")
if(hashInPathName) this.location.replace(this.root + this.prefix + hashInPathName);

}else if( this.mode === HISTORY /* && pathname === this.root*/){

hash = this.location.hash.replace(this.prefix, "");
if(hash) history.replaceState({}, document.title, _.cleanPath(this.root + hash))

var hash = this.location.hash.replace(this.prefix, "");
if( this.mode === HISTORY && hash) {
history.replaceState({}, document.title, _.cleanPath(this.root + hash));
} else {
var hashInPathName = _.cleanPath(this.location.pathname.replace(this.rRoot, ""));
if(this.html5) {
this.location.replace(this.root + this.prefix + hashInPathName);
} else {
this.location.hash = this.prefix + hashInPathName;
}
}
},
// Thanks for backbone.history and https://github.com/cowboy/jquery-hashchange/blob/master/jquery.ba-hashchange.js
Expand Down
23 changes: 10 additions & 13 deletions stateman.js
Original file line number Diff line number Diff line change
Expand Up @@ -1069,19 +1069,16 @@ return /******/ (function(modules) { // webpackBootstrap
// or we use hash in html5supoort mode (when paste url in other url)
// then , histery should repara it
_fixInitState: function(){
var pathname = _.cleanPath(this.location.pathname), hash, hashInPathName;

// dont support history popstate but config the html5 mode
if( this.mode !== HISTORY && this.html5){

hashInPathName = pathname.replace(this.rRoot, "")
if(hashInPathName) this.location.replace(this.root + this.prefix + hashInPathName);

}else if( this.mode === HISTORY /* && pathname === this.root*/){

hash = this.location.hash.replace(this.prefix, "");
if(hash) history.replaceState({}, document.title, _.cleanPath(this.root + hash))

var hash = this.location.hash.replace(this.prefix, "");
if( this.mode === HISTORY && hash) {
history.replaceState({}, document.title, _.cleanPath(this.root + hash));
} else {
var hashInPathName = _.cleanPath(this.location.pathname.replace(this.rRoot, ""));
if(this.html5) {
this.location.replace(this.root + this.prefix + hashInPathName);
} else {
this.location.hash = this.prefix + hashInPathName;
}
}
},
// Thanks for backbone.history and https://github.com/cowboy/jquery-hashchange/blob/master/jquery.ba-hashchange.js
Expand Down
Loading

0 comments on commit 12e4a73

Please sign in to comment.