Skip to content

Instantly share code, notes, and snippets.

@sammylupt
Created August 19, 2016 14:01
Show Gist options
  • Save sammylupt/d3429489b371004d171e85f0ce581635 to your computer and use it in GitHub Desktop.
Save sammylupt/d3429489b371004d171e85f0ce581635 to your computer and use it in GitHub Desktop.
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>
);
}
@htxiong
Copy link

htxiong commented Jun 5, 2017

Thanks, and same question from me, How to make store available for lookups? or is there anyway to make getState() be available?

@htxiong
Copy link

htxiong commented Jun 6, 2017

@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