Last active
February 21, 2018 03:41
-
-
Save abury/dc2448bfa70bcb1b04f773ade883e5f9 to your computer and use it in GitHub Desktop.
PlainRoute example with require auth for React-redux
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
// We only need to import the modules necessary for initial render | |
import CoreLayout from '../layouts/CoreLayout/CoreLayout'; | |
import Home from './Home'; | |
import LoginRoute from './Login'; | |
import SignupRoute from './Signup'; | |
import DashboardRoute from './Secure/Dashboard'; | |
import LeadsRoute from './Secure/Leads'; | |
import NotFound from './NotFound'; | |
/* Note: Instead of using JSX, we recommend using react-router | |
PlainRoute objects to build route definitions. */ | |
export default (store) => { | |
const requireLogin = (nextState, replace, cb) => { | |
const { session: { user } } = store.getState(); | |
if (!user) { | |
replace('login'); | |
} | |
cb(); | |
}; | |
const requirePublic = (nextState, replace, cb) => { | |
const { session: { user } } = store.getState(); | |
if (user) { | |
replace('dashboard'); | |
} | |
cb(); | |
}; | |
return ({ | |
path : '/', | |
indexRoute : Home, | |
component: CoreLayout, | |
childRoutes : [ | |
{ | |
onEnter: requireLogin, | |
childRoutes:[ | |
DashboardRoute(store), | |
LeadsRoute(store) | |
] | |
}, | |
{ | |
onEnter: requirePublic, | |
childRoutes: [ | |
LoginRoute(store), | |
SignupRoute(store) | |
] | |
}, | |
{ | |
path: '*', | |
indexRoute: NotFound, | |
status: 404 | |
} | |
] | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment