Created
August 19, 2016 14:01
-
-
Save sammylupt/d3429489b371004d171e85f0ce581635 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function loggedIn() { | |
// ... | |
} | |
function requireAuth(nextState, replace) { | |
if (!loggedIn()) { | |
replace({ | |
pathname: '/login' | |
}) | |
} | |
} | |
function routes() { | |
return ( | |
<Route path="/" component={App}> | |
<Route path="login" component={Login} /> | |
<Route path="logout" component={Logout} /> | |
<Route path="checkout" component={Checkout} onEnter={requireAuth} /> | |
</Route> | |
); | |
} |
@Gera3dartist FYI, I tested it and it works for me.
https://stackoverflow.com/questions/35849970/accessing-redux-store-from-routes-set-up-via-react-router
But the code need to be change a bit.
export const getRoutes = (store) => {
const authRequired = (nextState, replaceState) => {
....
};
return (
<Route path="/" component={App}>
<Route path="signup" component={SignUp} onEnter={authRequired}/>
</Route>
);
};
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, and same question from me, How to make store available for lookups? or is there anyway to make getState() be available?