Created
January 10, 2018 10:27
-
-
Save kaueDM/ae2ba1c6cd798e17aecf3ea05b0c93c3 to your computer and use it in GitHub Desktop.
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 React from 'react'; | |
import { connect } from 'react-redux'; | |
import { BrowserRouter, Switch, Route, Redirect } from 'react-router-dom'; | |
import { Login, Dashboard, Wrapper, Products, RoutineBuilder, RoutineOverview } from '../views'; | |
class Router extends React.Component { | |
render() { | |
return <BrowserRouter>{this._handleAuthentication()}</BrowserRouter> | |
} | |
_handleAuthentication = () => { | |
let { user } = this.props | |
if (!user) { | |
return ( | |
<Wrapper> | |
<Switch> | |
<Route exact path="/painel" component={Dashboard} /> | |
<Route exact path="/produtos" component={Products} /> | |
<Route exact path="/rotinas" component={RoutineOverview} /> | |
<Route exact path="/rotinas/builder" component={RoutineBuilder} /> | |
<Route render={() => <Redirect to="/dashboard" />} /> | |
</Switch> | |
</Wrapper> | |
) | |
} | |
if (user) { | |
return ( | |
<Switch> | |
<Route exact path="/" component={Login} /> | |
<Route render={() => <Redirect to="/" />} /> | |
</Switch> | |
) | |
} | |
} | |
} | |
const mapStateToProps = state => { | |
const { user } = state.auth | |
return { user } | |
} | |
export default connect(mapStateToProps, {})(Router) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment