Last active
June 23, 2018 21:20
-
-
Save ahlusar1989/d46edb1f73987838b358e05649624639 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
import React from 'react'; | |
import App from './containers/AppContainer'; | |
import Login from './containers/LoginContainer'; | |
import Signup from './containers/SignUpContainer'; | |
import MapContainer from './containers/MapContainer'; | |
import ListingsContainer from './containers/ListingsContainer'; | |
import createBrowserHistory from 'history/createBrowserHistory' | |
import { Router, Route, Switch, Redirect } from 'react-router-dom'; | |
const history = createBrowserHistory() | |
const checkAuth = () =>{ | |
const token = sessionStorage.getItem('token'); | |
return !!token | |
} | |
const AuthRoute = ({ component: Component, ...rest }) => ( | |
<Route {...rest} render={props => ( | |
checkAuth() ? ( | |
<Component {...props}/> | |
) : ( | |
<Redirect to={{ pathname: '/login'}} /> | |
) | |
)}/> | |
) | |
const Routes = () => { | |
return ( | |
<Router history = {history}> | |
<Switch> | |
<Route exact path="/login" render={props => <Login {...props} />} /> | |
<Route exact path="/signup" render={props => <Signup {...props} />} /> | |
<AuthRoute exact path="/" component={App} /> | |
<Route exact path="/listings" component={ListingsContainer} /> | |
<Route exact path="/predictions" component={MapContainer} /> | |
</Switch> | |
</Router> | |
) | |
}; | |
export default Routes; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment