diff --git a/packages/ember-routing/lib/location/history_location.js b/packages/ember-routing/lib/location/history_location.js index 20f7a223183..00d5a0246a9 100644 --- a/packages/ember-routing/lib/location/history_location.js +++ b/packages/ember-routing/lib/location/history_location.js @@ -84,7 +84,14 @@ export default EmberObject.extend({ this.supportsHistory = true; } - this.replaceState(this.formatURL(this.getURL())); + let state = this.getState(); + let path = this.formatURL(this.getURL()); + if (state && state.path === path) { // preserve existing state + // used for webkit workaround, since there will be no initial popstate event + this._previousURL = this.getURL(); + } else { + this.replaceState(path); + } }, /** diff --git a/packages/ember-routing/tests/location/history_location_test.js b/packages/ember-routing/tests/location/history_location_test.js index aa2a439170c..0bb9290535b 100644 --- a/packages/ember-routing/tests/location/history_location_test.js +++ b/packages/ember-routing/tests/location/history_location_test.js @@ -304,3 +304,25 @@ QUnit.test('HistoryLocation.getURL() drops duplicate slashes', function() { equal(location.getURL(), '/'); }); + +QUnit.test('Existing state is preserved on init', function() { + expect(1); + + let existingState = { + path: '/route/path', + uuid: 'abcd' + }; + + FakeHistory.state = existingState; + + HistoryTestLocation.reopen({ + init() { + this._super(...arguments); + set(this, 'location', mockBrowserLocation('/route/path')); + } + }); + + createLocation(); + location.initState(); + deepEqual(location.getState(), existingState); +});