Skip to content
This repository was archived by the owner on Oct 26, 2018. It is now read-only.

Fix basename path issues #104

Merged
merged 1 commit into from
Dec 10, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand All @@ -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
}

Expand Down
17 changes: 17 additions & 0 deletions test/createTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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
})
})
})
}