diff --git a/modules/__tests__/describeBasename.js b/modules/__tests__/describeBasename.js index 52b30b270..8a2329d69 100644 --- a/modules/__tests__/describeBasename.js +++ b/modules/__tests__/describeBasename.js @@ -22,7 +22,7 @@ function describeBasename(createHistory) { unlisten() }) - describe('in push', function () { + describe('in pushState', function () { it('works', function (done) { let steps = [ function (location) { @@ -31,7 +31,7 @@ function describeBasename(createHistory) { expect(location.state).toEqual(null) expect(location.action).toEqual(POP) - history.push('/home', { the: 'state' }) + history.pushState({ the: 'state' }, '/home') }, function (location) { expect(location.pathname).toEqual('/home') @@ -45,7 +45,7 @@ function describeBasename(createHistory) { }) }) - describe('in pushState', function () { + describe('in push', function () { it('works', function (done) { let steps = [ function (location) { @@ -54,12 +54,12 @@ function describeBasename(createHistory) { expect(location.state).toEqual(null) expect(location.action).toEqual(POP) - history.pushState({ the: 'state' }, '/home') + history.push('/home') }, function (location) { expect(location.pathname).toEqual('/home') expect(location.search).toEqual('') - expect(location.state).toEqual({ the: 'state' }) + expect(location.state).toEqual(null) expect(location.action).toEqual(PUSH) } ] @@ -100,12 +100,12 @@ function describeBasename(createHistory) { expect(location.state).toEqual(null) expect(location.action).toEqual(POP) - history.replace('/home', { the: 'state' }) + history.replace('/home') }, function (location) { expect(location.pathname).toEqual('/home') expect(location.search).toEqual('') - expect(location.state).toEqual({ the: 'state' }) + expect(location.state).toEqual(null) expect(location.action).toEqual(REPLACE) } ] diff --git a/modules/__tests__/describePush.js b/modules/__tests__/describePush.js index 8b154352c..63389460a 100644 --- a/modules/__tests__/describePush.js +++ b/modules/__tests__/describePush.js @@ -16,27 +16,6 @@ function describePush(createHistory) { }) it('calls change listeners with the new location', function (done) { - let steps = [ - function (location) { - expect(location.pathname).toEqual('/') - expect(location.search).toEqual('') - expect(location.state).toEqual(null) - expect(location.action).toEqual(POP) - - history.push('/home?the=query', { the: 'state' }) - }, - function (location) { - expect(location.pathname).toEqual('/home') - expect(location.search).toEqual('?the=query') - expect(location.state).toEqual({ the: 'state' }) - expect(location.action).toEqual(PUSH) - } - ] - - unlisten = history.listen(execSteps(steps, done)) - }) - - it('calls change listeners with the new location without state argument', function (done) { let steps = [ function (location) { expect(location.pathname).toEqual('/') @@ -56,7 +35,6 @@ function describePush(createHistory) { unlisten = history.listen(execSteps(steps, done)) }) - }) } diff --git a/modules/__tests__/describeQueries.js b/modules/__tests__/describeQueries.js index d1d454f92..5c9c60a5a 100644 --- a/modules/__tests__/describeQueries.js +++ b/modules/__tests__/describeQueries.js @@ -52,31 +52,6 @@ function describeQueries(createHistory) { }) }) - describe('in push', function () { - it('works', function (done) { - let steps = [ - function (location) { - expect(location.pathname).toEqual('/') - expect(location.search).toEqual('') - expect(location.query).toEqual('PARSE_QUERY_STRING') - expect(location.state).toEqual(null) - expect(location.action).toEqual(POP) - - history.push('/home', { the: 'query' }, { the: 'state' }) - }, - function (location) { - expect(location.pathname).toEqual('/home') - expect(location.search).toEqual('?STRINGIFY_QUERY') - expect(location.query).toEqual('PARSE_QUERY_STRING') - expect(location.state).toEqual({ the: 'state' }) - expect(location.action).toEqual(PUSH) - } - ] - - unlisten = history.listen(execSteps(steps, done)) - }) - }) - describe('in replaceState', function () { it('works', function (done) { let steps = [ @@ -102,31 +77,6 @@ function describeQueries(createHistory) { }) }) - describe('in replace', function () { - it('works', function (done) { - let steps = [ - function (location) { - expect(location.pathname).toEqual('/') - expect(location.search).toEqual('') - expect(location.query).toEqual('PARSE_QUERY_STRING') - expect(location.state).toEqual(null) - expect(location.action).toEqual(POP) - - history.replace('/home', { the: 'query' }, { the: 'state' }) - }, - function (location) { - expect(location.pathname).toEqual('/home') - expect(location.search).toEqual('?STRINGIFY_QUERY') - expect(location.query).toEqual('PARSE_QUERY_STRING') - expect(location.state).toEqual({ the: 'state' }) - expect(location.action).toEqual(REPLACE) - } - ] - - unlisten = history.listen(execSteps(steps, done)) - }) - }) - describe('in createPath', function () { it('works', function () { expect( diff --git a/modules/__tests__/describeReplace.js b/modules/__tests__/describeReplace.js index 884d9bd36..851be1f9b 100644 --- a/modules/__tests__/describeReplace.js +++ b/modules/__tests__/describeReplace.js @@ -16,27 +16,6 @@ function describeReplace(createHistory) { }) it('calls change listeners with the new location', function (done) { - let steps = [ - function (location) { - expect(location.pathname).toEqual('/') - expect(location.search).toEqual('') - expect(location.state).toEqual(null) - expect(location.action).toEqual(POP) - - history.replace('/home?the=query', { the: 'state' }) - }, - function (location) { - expect(location.pathname).toEqual('/home') - expect(location.search).toEqual('?the=query') - expect(location.state).toEqual({ the: 'state' }) - expect(location.action).toEqual(REPLACE) - } - ] - - unlisten = history.listen(execSteps(steps, done)) - }) - - it('calls change listeners with the new location without state argument', function (done) { let steps = [ function (location) { expect(location.pathname).toEqual('/') @@ -49,7 +28,7 @@ function describeReplace(createHistory) { function (location) { expect(location.pathname).toEqual('/home') expect(location.search).toEqual('?the=query') - expect(location.state).toEqual(null) + expect(location.state).toEqual() expect(location.action).toEqual(REPLACE) } ] diff --git a/modules/createHistory.js b/modules/createHistory.js index 6abcf2a72..3de46068b 100644 --- a/modules/createHistory.js +++ b/modules/createHistory.js @@ -132,18 +132,18 @@ function createHistory(options={}) { ) } + function push(path) { + pushState(null, path) + } + function replaceState(state, path) { transitionTo( createLocation(path, state, REPLACE, createKey()) ) } - function push(path, state) { - pushState(state, path) - } - - function replace(path, state) { - replaceState(state, path) + function replace(path) { + replaceState(null, path) } function goBack() { diff --git a/modules/useBasename.js b/modules/useBasename.js index a417655c4..c45347221 100644 --- a/modules/useBasename.js +++ b/modules/useBasename.js @@ -68,16 +68,16 @@ function useBasename(createHistory) { history.pushState(state, prependBasename(path)) } - function replaceState(state, path) { - history.replaceState(state, prependBasename(path)) + function push(path) { + pushState(null, path) } - function push(path, state) { - pushState(state, path) + function replaceState(state, path) { + history.replaceState(state, prependBasename(path)) } - function replace(path, state) { - replaceState(state, path) + function replace(path) { + replaceState(null, path) } function createPath(path) { diff --git a/modules/useQueries.js b/modules/useQueries.js index adce67889..f63a75853 100644 --- a/modules/useQueries.js +++ b/modules/useQueries.js @@ -70,14 +70,6 @@ function useQueries(createHistory) { return history.replaceState(state, appendQuery(path, query)) } - function push(path, query, state) { - return history.push(appendQuery(path, query), state) - } - - function replace(path, query, state) { - return history.replace(appendQuery(path, query), state) - } - function createPath(path, query) { return history.createPath(appendQuery(path, query)) } @@ -96,8 +88,6 @@ function useQueries(createHistory) { listen, pushState, replaceState, - push, - replace, createPath, createHref, createLocation