App.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import 'antd/dist/antd.min.css'
  2. import './App.scss';
  3. import { Router, Route, Switch, Redirect } from 'react-router-dom';
  4. import createHistory from "history/createBrowserHistory";
  5. import { connect, Provider } from 'react-redux';
  6. import store from './redux/redux-store';
  7. import { Authorization } from './components/Authorization';
  8. import { Container, Content, Main } from './pages/Content';
  9. import { CProfilePage } from './pages/ProfilePage';
  10. import { CAdd } from './components/main/Add';
  11. import HeaderComponent from './pages/Header';
  12. import { CMainPostsFeed } from './pages/MainPostsFeed';
  13. import { CRRoute } from './helpers';
  14. import { CPostPage } from './pages/PostPage';
  15. import { CAllPosts } from './pages/AllPosts';
  16. import { CEntityEditorPost } from './pages/EntityEditorPost';
  17. export const history = createHistory()
  18. const Aside = () =>
  19. <div>sdfsdgsgsdg</div>
  20. const AppContent = ({ isToken }) =>
  21. <Router history={history}>
  22. {!isToken
  23. ?
  24. <Switch>
  25. <Route path='/auth/:_id'
  26. component={Authorization} />
  27. <Redirect from='/*' to='/auth/login' />
  28. </Switch>
  29. :
  30. <Content>
  31. <HeaderComponent />
  32. <Main>
  33. <Container>
  34. <Route path='/' component={CMainPostsFeed} exact />
  35. <Route path='/profile/:_id' component={CProfilePage} />
  36. <Route path='/message' component={Aside} />
  37. {/* <Route path='/add' component={CAdd} /> */}
  38. <Route path='/add' component={CEntityEditorPost} />
  39. <CRRoute path='/all' component={CAllPosts} />
  40. </Container>
  41. <CRRoute path='/post/:id' component={CPostPage} />
  42. {/* <Redirect from='/*' to='/' /> */}
  43. </Main>
  44. </Content >
  45. // <Switch>
  46. // <Route path='/' component={Content} exact />
  47. // <Redirect from='/auth/*' to='/' />
  48. // </Switch>
  49. }
  50. </Router >
  51. const CAppContent = connect(state => ({ isToken: state.auth?.token }))(AppContent)
  52. store.subscribe(() => console.log(store.getState()))
  53. function App() {
  54. return (
  55. <Provider store={store}>
  56. <CAppContent />
  57. </Provider>
  58. )
  59. }
  60. export default App;