Created
November 10, 2015 04:32
-
-
Save wyze/d70fdc94bfe4e3d3f9ef to your computer and use it in GitHub Desktop.
Redux state passed to onEnter of react-router.
This file contains hidden or 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
import createHistory from 'history/lib/createBrowserHistory'; | |
import createStore from './redux/createStore'; | |
import createRoutes from './routes'; | |
import React from 'react'; | |
import { Provider } from 'react-redux'; | |
import { Router } from 'react-router'; | |
import { render } from 'react-dom'; | |
const history = createHistory(); | |
const store = createStore(history, window.__data); | |
render(( | |
<Provider store={store}> | |
<Router history={history}> | |
{createRoutes(store)} | |
</Router> | |
</Provider> | |
), document.getElementById('root')); |
This file contains hidden or 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
export default store => | |
( nextState, replaceState ) => { | |
if ( !store.getState().auth.user ) { | |
replaceState({ nextPathname: nextState.location.pathname }, '/'); | |
} | |
}; |
This file contains hidden or 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
import AppContainer from '../containers/AppContainer'; | |
import createRequireAuth from './createRequireAuth'; | |
import DashboardContainer from '../containers/DashboardContainer'; | |
import HomeContainer from '../containers/HomeContainer'; | |
import React from 'react'; | |
import { Redirect, Route } from 'react-router'; | |
export default store => ( | |
<Route component={AppContainer}> | |
<Route path="/" component={HomeContainer} /> | |
<Route onEnter={createRequireAuth(store)}> | |
<Route path="dashboard" component={DashboardContainer} /> | |
</Route> | |
</Route> | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment