diff --git a/__tests__/__snapshots__/createLocationReducer.js.snap b/__tests__/__snapshots__/createLocationReducer.js.snap index e628f1b3..453735e9 100644 --- a/__tests__/__snapshots__/createLocationReducer.js.snap +++ b/__tests__/__snapshots__/createLocationReducer.js.snap @@ -41,6 +41,47 @@ Object { } `; +exports[`createLocationReducer() - reduces action.meta.location.kind being updated 1`] = ` +Object { + "hasSSR": undefined, + "history": Object { + "entries": Array [ + Object { + "hash": "", + "key": "345678", + "pathname": "/first", + "search": "", + "state": undefined, + }, + Object { + "hash": "", + "key": "345678", + "pathname": "/first", + "search": "", + "state": undefined, + }, + ], + "index": 1, + "length": 2, + }, + "kind": "load", + "pathname": "/first", + "payload": Object { + "param": "bar", + }, + "prev": Object { + "pathname": "/first", + "payload": Object {}, + "type": "FIRST", + }, + "routesMap": Object { + "FIRST": "/first", + "SECOND": "/second/:param", + }, + "type": "FIRST", +} +`; + exports[`getInitialState() returns state.history === undefined when using createBrowserHistory 1`] = ` Object { "hasSSR": undefined, diff --git a/__tests__/createLocationReducer.js b/__tests__/createLocationReducer.js index 0d31b41c..cbbe9479 100644 --- a/__tests__/createLocationReducer.js +++ b/__tests__/createLocationReducer.js @@ -17,6 +17,30 @@ it('createLocationReducer() - maintains address bar pathname state and current + expectState(state) }) +it('createLocationReducer() - reduces action.meta.location.kind being updated', () => { + const { initialState, action, routesMap, expectState } = reducerParameters( + 'FIRST', + '/first' + ) + + const reducer = createLocationReducer(initialState, routesMap) + const state = reducer(undefined, action) /*? */ + + const nextAction = { + ...action, + meta: { + location: { + ...action.meta.location, + kind: 'push' + } + } + } + const nextState = reducer(state, nextAction) /*? */ + + expectState(state) + expect(nextState.kind).toEqual('push') +}) + it('locationReducer() reduces action.type === NOT_FOUND', () => { const { initialState, routesMap, action } = reducerParameters( NOT_FOUND, diff --git a/src/reducer/createLocationReducer.js b/src/reducer/createLocationReducer.js index cb88fee1..4c5b1c8d 100644 --- a/src/reducer/createLocationReducer.js +++ b/src/reducer/createLocationReducer.js @@ -41,6 +41,20 @@ export default (initialState: LocationState, routesMap: RoutesMap) => ( routesMap } } + else if ( + route && + !action.error && + (typeof route === 'string' || route.path) && + (action.meta.location.current.pathname === state.pathname && + action.meta.location.current.search === state.search && + action.meta.location.kind !== state.kind + ) + ) { + return { + ...state, + kind: action.meta.location.kind + } + } else if (action.type === ADD_ROUTES) { return { ...state,