Skip to content

Commit

Permalink
Merge pull request #228 from mjrussell/server-history-removal
Browse files Browse the repository at this point in the history
Require createHistory to be passed in server rendering options
  • Loading branch information
Franz committed Jan 2, 2016
2 parents bf5107f + cd3c803 commit 057bfba
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
18 changes: 15 additions & 3 deletions src/__tests__/ReduxRouter-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ describe('<ReduxRouter>', () => {
router: routerStateReducer
});

const store = server.reduxReactRouter({ routes })(createStore)(reducer);
const store = server.reduxReactRouter({ routes, createHistory })(createStore)(reducer);
store.dispatch(server.match('/parent/child/850?key=value', (err, redirectLocation, routerState) => {
const output = renderToString(
<Provider store={store}>
Expand All @@ -173,7 +173,7 @@ describe('<ReduxRouter>', () => {
router: routerStateReducer
});

const store = server.reduxReactRouter({ routes })(createStore)(reducer);
const store = server.reduxReactRouter({ routes, createHistory })(createStore)(reducer);
expect(() => store.dispatch(server.match('/404', () => {})))
.to.not.throw();
});
Expand All @@ -193,12 +193,24 @@ describe('<ReduxRouter>', () => {
);
});

it('throws if createHistory is not passed to store enhancer', () => {
const reducer = combineReducers({
router: routerStateReducer
});

expect(() => server.reduxReactRouter({ routes })(createStore)(reducer))
.to.throw(
'When rendering on the server, createHistory must be passed to the '
+ 'reduxReactRouter() store enhancer'
);
});

it('handles redirects', () => {
const reducer = combineReducers({
router: routerStateReducer
});

const store = server.reduxReactRouter({ routes })(createStore)(reducer);
const store = server.reduxReactRouter({ routes, createHistory })(createStore)(reducer);
store.dispatch(server.match('/redirect', (error, redirectLocation) => {
expect(error).to.be.null;
expect(redirectLocation.pathname).to.equal('/parent/child/850');
Expand Down
13 changes: 7 additions & 6 deletions src/server.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { compose, applyMiddleware } from 'redux';
import createMemoryHistory from 'history/lib/createMemoryHistory';
import baseReduxReactRouter from './reduxReactRouter';
import useDefaults from './useDefaults';
import routeReplacement from './routeReplacement';
Expand All @@ -16,6 +15,12 @@ function serverInvariants(next) {
+ 'between routes and the store, use the option getRoutes(store).'
);
}
if (!options || !(options.createHistory)) {
throw new Error(
'When rendering on the server, createHistory must be passed to the '
+ 'reduxReactRouter() store enhancer'
);
}

return next(options)(createStore);
};
Expand All @@ -31,11 +36,7 @@ function matching(next) {
store.history.match(location, callback);
})
),
next({
...options,
createHistory: options.createHistory || createMemoryHistory
})
)(createStore)(reducer, initialState);
next(options))(createStore)(reducer, initialState);
return store;
};
}
Expand Down

0 comments on commit 057bfba

Please sign in to comment.