diff --git a/src/index.js b/src/index.js index 10cb737..495ec76 100644 --- a/src/index.js +++ b/src/index.js @@ -71,6 +71,16 @@ function locationsAreEqual(a, b) { return a != null && b != null && a.path === b.path && deepEqual(a.state, b.state) } +function createPath(location) { + const { pathname, search, hash } = location + let result = pathname + if (search) + result += search + if (hash) + result += hash + return result +} + function syncReduxAndRouter(history, store, selectRouterState = SELECT_STATE) { const getRouterState = () => selectRouterState(store.getState()) @@ -92,7 +102,7 @@ function syncReduxAndRouter(history, store, selectRouterState = SELECT_STATE) { const unsubscribeHistory = history.listen(location => { const route = { - path: history.createPath(location), + path: createPath(location), state: location.state } diff --git a/test/createTests.js b/test/createTests.js index d126800..a1f6e96 100644 --- a/test/createTests.js +++ b/test/createTests.js @@ -5,6 +5,7 @@ const { pushPath, replacePath, UPDATE_PATH, routeReducer, syncReduxAndRouter } = const { createStore, combineReducers, compose } = require('redux') const { devTools } = require('redux-devtools') const { ActionCreators } = require('redux-devtools/lib/devTools') +const { useBasename } = require('history') expect.extend({ toContainRoute({ @@ -602,5 +603,21 @@ module.exports = function createTests(createHistory, name, reset = defaultReset) ).toNotThrow() }) }) + + it('handles basename history option', () => { + const store = createStore(combineReducers({ + routing: routeReducer + })) + const history = useBasename(createHistory)({ basename:'/foobar' }) + syncReduxAndRouter(history, store) + + store.dispatch(pushPath('/bar')) + expect(store).toContainRoute({ + path: '/bar', + changeId: 2, + replace: false, + state: undefined + }) + }) }) }