-
Notifications
You must be signed in to change notification settings - Fork 216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
store not available for hooks #32
Comments
it would be great to have an api like: function routes(dispatch, getState) {
function requireAuth(nextState, redirectTo) {
const { user } = getState();
// ...
}
return {
component: Application,
onEnter: requireAuth,
childRoutes: [ /* ... */ ]
};
}
const store = compose(
reduxReactRouter({
routes,
createHistory
})
)(createStore)(reducer); |
Hmm yeah that might work. I've been thinking about this, too. Might be best to split it into a separate option called |
👍 Really like the idea of being able to prove the routes with a dispatcher and state, otherwise the routing logic gets pushed down to the components |
Closed by dabfb3b |
Cool! thx! |
Was solving same problem and was happy to find const getRoutes = ({ dispatch, getState }) => {
function requireAuth(nextState, replaceState) {
console.log(getState()); // <-- EXCEPTION is thown here...
}
return (
<Route path="/" component={App}>
<Route path="sign-up" component={SignUp} />
<Route path="account" onEnter={requireAuth} />
</Route>
);
};
const configureStore = compose(
applyMiddleware(thunk),
reduxReactRouter({
getRoutes,
createHistory
})
)(createStore);
const store = configureStore(rootReducer);
const Root = (
<Provider store={store}>
<ReduxRouter />
</Provider>
);
ReactDom.render(Root, document.getElementById('main')); As you can see, I use
In react-redux-universal-hot-example they are using special helper, that patches But for me, it looks more as workaround not a solution. |
Ok, I got a little more into the issues of that project and some conclusions I got. It's not that actively maintened any more, and there is an issue also complaining about same problem. There is also ongoing discussion in this pull request. I put that just for summary and let's have a discussion in one place. |
Fixed by swapping two lines of code. |
Hey, great work you're doing with redux-react-router!
I tested the
next
implementation with an existing project that relies on theonEnter
hook for authentication. The problem I'm facing is that the store is not available when routes invoke these hooks.Example
Any ideas how to make the store available for the
onEnter
hook?The text was updated successfully, but these errors were encountered: