Skip to content

Commit

Permalink
[BUGFIX beta] Preserve current history state
Browse files Browse the repository at this point in the history
  • Loading branch information
courajs committed May 10, 2017
1 parent 1e5b8a9 commit d63f82c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/ember-routing/lib/location/history_location.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,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);
}
},

/**
Expand Down
22 changes: 22 additions & 0 deletions packages/ember-routing/tests/location/history_location_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

0 comments on commit d63f82c

Please sign in to comment.