diff --git a/src/Routes.js b/src/Routes.js index f84b2b2e..fe3aa73c 100644 --- a/src/Routes.js +++ b/src/Routes.js @@ -1,25 +1,53 @@ import React, { PropTypes } from 'react'; -// import { Miss } from 'react-router-dom'; -import { RouterProvider, RoutesProvider } from './components'; -// import { NotFoundPage, MatchWithSubRoutes } from './containers'; -import { flattenRoutes } from './routesConfiguration'; +import { connect } from 'react-redux'; +import { Switch, Route } from 'react-router-dom'; +import { NotFoundPage } from './containers'; +import { NamedRedirect } from './components'; const Routes = props => { - const flattenedRoutes = flattenRoutes(props.routes); - // const matches = flattenedRoutes.map(route => ); + const { isAuthenticated, routes } = props; + + const renderComponent = (route, match) => { + const { auth, component: Component } = route; + const canShowComponent = !auth || isAuthenticated; + return canShowComponent + ? + : ; + }; + + const toRouteComponent = route => ( + renderComponent(route, matchProps.match)} + /> + ); return ( - - - {/*matches*/} - {/**/} - - + + {routes.map(toRouteComponent)} + + ); }; -const { any, array } = PropTypes; +const { bool, arrayOf, shape, string, func } = PropTypes; -Routes.propTypes = { routes: array.isRequired }; +Routes.propTypes = { + isAuthenticated: bool.isRequired, + routes: arrayOf( + shape({ + name: string.isRequired, + pattern: string.isRequired, + exactly: bool, + strict: bool, + component: func.isRequired, + loadData: func, + }), + ).isRequired, +}; -export default Routes; +const mapStateToProps = state => ({ isAuthenticated: state.Auth.isAuthenticated }); + +export default connect(mapStateToProps)(Routes);