// Component const RoutePrivate = (props) => ( props.user.isAuthenticated ? props.role ? props.user.details.role === props.role ? <Route {...props} component={props.component}/> : <Redirect to={userRoutes.login.path}/> : <Route {...props} component={props.component}/> : <Redirect to={userRoutes.login.path}/> )
const SectionRoute = ({ title, ...props }) => ( <App title={title}> <Route {...props} /> </App> )
function createElements (history) { const elements = [ <Router key="router" history={history} children={routes} /> ] if (typeof __DEVTOOLS__ !== 'undefined' && __DEVTOOLS__) { /*eslint-disable*/ const DevTools = require('./DevTools') /*eslint-enable*/ elements.push(<DevTools key="devtools" />) } return elements }
const MenuItem = ({ to, title, icon, seletedPaths }) => { const { pathname } = useLocation(); const selected = (seletedPaths || [to]).some(path => matchPath(pathname, {path: path, exact: true})) return ( <ListItem button to={to} component={Link} selected={selected}> <ListItemIcon> {icon} </ListItemIcon> <ListItemText primary={title} /> </ListItem> ) }
const App = () => ( <Layout> <Switch> {Object.values(routes).map((route, index) => ( route.auth ? <RoutePrivate {...route} key={index} path={typeof route.path === 'function' ? route.path() : route.path}/> : <Route {...route} key={index} path={typeof route.path === 'function' ? route.path() : route.path}/> ))} <Route component={NotFound}/> </Switch> </Layout> )
render(( <Router id="UA-46921629-2"> <Route path="/" render={ props => ( <Site { ...props } import={ path => import(`./content/${path}`) } /> )} /> </Router> ), document.getElementById('root'));
const MainLayout = () => { const classes = useStyles(); return ( <div className={classes.root}> <TopBar /> <div className={classes.wrapper}> <div className={classes.contentContainer}> <div className={classes.content}> <Outlet /> </div> </div> </div> </div> ); }
render() { const { component: Component, ...rest } = this.props; const { isAuthed } = this.state; if (isAuthed) { return <Route {...rest} render={props => <Component {...props} />} />; } return null; }
// Component const AuthAdminCheck = (props) => ( props.user.isAuthenticated && props.user.details.role === 'ADMIN' ? '' : <Redirect to={home.home.path}/> )
// Component const RoutePrivate = (props) => ( props.user.isAuthenticated ? props.role ? props.user.details.role === props.role ? <Route {...props} component={props.component}/> : <Redirect to={userRoutes.login.path}/> : <Route {...props} component={props.component}/> : <Redirect to={userRoutes.login.path}/> )
const App = () => ( <Layout> <Switch> {Object.values(routes).map((route, index) => ( route.auth ? <RoutePrivate {...route} key={index} path={typeof route.path === 'function' ? route.path() : route.path}/> : <Route {...route} key={index} path={typeof route.path === 'function' ? route.path() : route.path}/> ))} <Route component={NotFound}/> </Switch> </Layout> )
// Component const AuthAdminCheck = (props) => ( props.user.isAuthenticated && props.user.details.role === 'ADMIN' ? '' : <Redirect to={home.home.path}/> )