getRoutes() is back
It turns out that the dynamic routes feature from the last release won't work for server-side rendering, because the routes need to be specified before calling match()
. You must pass routes
(or getRoutes()
— see below) directly to the reduxReactRouter()
store enhancer when doing server-side rendering. We throw an error if you don't.
This makes circular dependencies (routes depend on store, store depends on routes) more difficult on the server, so this release also brings back a modified version of getRoutes()
.
reduxReactRouter({
getRoutes({ getState, dispatch }) {
// Return routes configuration
}
})
Note that you can always use a closure to work around a circular dependency:
let store;
function doSomethingOnEnter() {
store.dispatch(whatever);
}
const routes = (
<Route>
<Router path="/" onEnter={doSomethingOnEnter} />
</Route>
);
store = reduxReactRouter({ routes })(createStore)(reducer, initialState);
This is essentially what getRoutes()
does for you.
Thank you to everybody who has been testing the betas so we can identify and fix issues like these! I am optimistic about a stable 1.0 release coming out soon (or whenever React Router releases their 1.0).