Skip to content

Instantly share code, notes, and snippets.

@ahlusar1989
Last active June 23, 2018 21:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahlusar1989/d46edb1f73987838b358e05649624639 to your computer and use it in GitHub Desktop.
Save ahlusar1989/d46edb1f73987838b358e05649624639 to your computer and use it in GitHub Desktop.
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