Skip to content

Commit 7d615df

Browse files
committed
Better HistoryLocation popstate handling - Fixes emberjs#2234
1 parent f0e6688 commit 7d615df

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

packages/ember-routing/lib/location/history_location.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
var get = Ember.get, set = Ember.set;
7-
var popstateReady = false;
7+
var popstateFired = false;
88

99
/**
1010
Ember.HistoryLocation implements the location API using the browser's
@@ -18,6 +18,7 @@ Ember.HistoryLocation = Ember.Object.extend({
1818

1919
init: function() {
2020
set(this, 'location', get(this, 'location') || window.location);
21+
this._initialUrl = this.getURL();
2122
this.initState();
2223
},
2324

@@ -70,7 +71,6 @@ Ember.HistoryLocation = Ember.Object.extend({
7071
path = this.formatURL(path);
7172

7273
if (this.getState() && this.getState().path !== path) {
73-
popstateReady = true;
7474
this.pushState(path);
7575
}
7676
},
@@ -88,7 +88,6 @@ Ember.HistoryLocation = Ember.Object.extend({
8888
path = this.formatURL(path);
8989

9090
if (this.getState() && this.getState().path !== path) {
91-
popstateReady = true;
9291
this.replaceState(path);
9392
}
9493
},
@@ -142,8 +141,10 @@ Ember.HistoryLocation = Ember.Object.extend({
142141
self = this;
143142

144143
Ember.$(window).bind('popstate.ember-location-'+guid, function(e) {
145-
if(!popstateReady) {
146-
return;
144+
// Ignore initial page load popstate event in Chrome
145+
if(!popstateFired) {
146+
popstateFired = true;
147+
if (self.getURL() === self._initialUrl) { return; }
147148
}
148149
callback(self.getURL());
149150
});

0 commit comments

Comments
 (0)