return (console.log('route', route),
<Route
key={i}
path={'/account/tickets'}
component={route.component}
/>
);
import Component from './components';
import connect from './containers/connect';
import lifecycle from './containers/lifecycle';
import withHandlers from './containers/withHandlers';
import { compose } from 'ramda';
export default compose(
connect,
withHandlers,
lifecycle
)(Component);
import React from 'react';
import { Route, Switch } from 'react-router-dom';
import AccessRoute from '../../../../common/AccessRoute';
import NavBar from './NavBar';
import Header from './Header';
import { Col, Container, Row } from 'react-bootstrap';
export default props => {
// debugger
return (
<div className="App main-content">
<Header />
<Container className="clearfix">
<Col sm={3} md={3}>
<NavBar list={props.data.menuList} />
</Col>
<Col sm={9} md={9} className="page-wrapper">
<div className="page-content">
<Switch>
{props.admin.routes.length
? props.admin.routes.map((route, i) => {
if (route.protectedRoute) { //пока что всегда false
return (
<AccessRoute
key={i}
path={'/account/tickets'}
render={() => route.component}
/>
);
}
return (
<Route
key={i}
path={'/account/tickets'}
render={() => route.component}
/>
);
})
: null}
</Switch>
</div>
</Col>
</Container>
</div>
);
};
app
└account
└tickets
export interface Module {
start(): void;
}
const AppComponent = () => (
<Provider store={this.store}>
<ApolloProvider client={client}>
<Router>
<Switch>
{this.routes.map((route: any, i: number) => {
if (route.protectedRoute) {
return (
<AccessRoute
exact
key={i}
path={route.path}
component={route.component}
/>
);
}
return (
<Route
exact
key={i}
path={route.path}
component={route.component}
/>
);
})}
</Switch>
</Router>
</ApolloProvider>
</Provider>
);
ReactDOM.render(<AppComponent />, document.getElementById('root'));
routes: ModuleRoute[] = [];
addRoute(route: ModuleRoute) {
this.routes.push(route)
}
constructor(app: IApp) {
this.component = withProps({ admin: this })(AdminPanel);
this.app = app;
this.links = [];
this.reducer = {
name: 'accountPanel',
reducer
}
this.app.addReducer(this.reducer)
this.app.addRoute({path: '/', component: this.component, protectedRoute: false});
this.app.addRoute({path: '/account', component: this.component, protectedRoute: false});
}
import TicketChoise from './Tickets';
export class ModuleTickets implements Module {
constructor(
app: IApp,
routeContainer: IRouteContainer,
menuContainer: ISidebar
) {
this.component = {
choise: TicketChoise
};
this.reducer = {
name: 'tickets',
reducer
};
this.routeContainer = routeContainer;
this.routeContainer.addRoute({
path: '/account/tickets/choice',
component: this.component.choise,
protectedRoute: false
});
this.routeContainer.addRoute({
path: '/account/tickets',
component: this.component.choise,
protectedRoute: false
});
}
}
const moduleTickets = new ModuleTickets(app, moduleAccount);
export default props => {
debugger
return (
<div className="App main-content">
//...
Boolean([].length) === false