App.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import { configureStore } from '@reduxjs/toolkit';
  2. import { Router, Route, Switch, useParams } from 'react-router-dom';
  3. import { createBrowserHistory } from "history";
  4. import { createStore, combineReducers, applyMiddleware } from 'redux';
  5. import { Provider } from 'react-redux';
  6. import { authReducer, promiseReducer, actionAuthLogin, frontEndReducer, actionRootCats } from './reducers';
  7. import { CLoginForm, CMainAppBar, COrdersList } from "./Components";
  8. import { CLogout } from './Components';
  9. import { CSidebar } from './Components/Sidebar';
  10. import thunk from 'redux-thunk';
  11. import { CRootCats } from './Components';
  12. import './App.css';
  13. import { CCategory } from './Components/Category';
  14. export const history = createBrowserHistory();
  15. //export const store = createStore(combineReducers({ promise: promiseReducer, auth: authReducer, frontend: frontEndReducer }), applyMiddleware(thunk));
  16. export const store = configureStore({
  17. reducer: {
  18. auth: authReducer,
  19. promise: promiseReducer,
  20. frontend: frontEndReducer
  21. }
  22. });
  23. store.subscribe(() => console.log(store.getState()))
  24. //console.log(useParams)
  25. store.dispatch(actionAuthLogin(localStorage.authToken));
  26. store.dispatch(actionRootCats());
  27. console.log('TTTTT' + performance.now())
  28. const NotFound = () =>
  29. <div>
  30. <h1>404 not found</h1>
  31. </div>
  32. const Main = () =>
  33. <div>
  34. <h1>Main page</h1>
  35. </div>
  36. function App() {
  37. return (
  38. <>
  39. <Router history={history}>
  40. <Provider store={store}>
  41. <div className="App">
  42. <CMainAppBar />
  43. <CSidebar menuComponent={() => <CRootCats />} />
  44. <Switch>
  45. <Route path="/" component={Main} exact />
  46. <Route path="/orders" component={COrdersList} />
  47. <Route path="/category/:_id" component={CCategory} />
  48. <Route path="/login" component={CLoginForm} />
  49. <Route path="/logout" component={CLogout} />
  50. <Route path="*" component={NotFound} />
  51. </Switch>
  52. </div>
  53. </Provider>
  54. </Router>
  55. </>
  56. );
  57. }
  58. {/* <div className="App">
  59. <header className="App-header">
  60. <img src={logo} className="App-logo" alt="logo" />
  61. <p>
  62. Edit <code>src/App.js</code> and save to reload.
  63. </p>
  64. <a
  65. className="App-link"
  66. href="https://reactjs.org"
  67. target="_blank"
  68. rel="noopener noreferrer"
  69. >
  70. Learn React
  71. </a>
  72. </header>
  73. </div>
  74. */}
  75. {/*<Route path="/" component={Main} exact />*/ }
  76. {/*<CCatMenu />
  77. <Route path="*" component={NotFound} />
  78. <LoginForm onLogin={(l, p) => console.log(l, p)} />
  79. <CLoginForm />
  80. <MyLink to="/" activeClassName='activeLink'>Главная</MyLink>
  81. <MyLink to="/aboutus" activeClassName='activeLink'>О нас</MyLink>
  82. <MyLink to="/add/2/3" activeClassName='activeLink'>2 + 3</MyLink>
  83. <MyLink to="/add/20/50" activeClassName='activeLink'>20 + 50</MyLink>
  84. <h1>Этот текст будет всегда в независимости от роутинга</h1>
  85. <Switch>
  86. <Route path="/" component={Main} exact />
  87. <Route path="/aboutus" component={AboutUs} />
  88. <Route path="/add/:a/:b" component={Add} />
  89. <Route path="*" component={NotFound} />
  90. </Switch>
  91. <h1>Роутинг выше</h1>*/}
  92. {/*
  93. <GoodsList goods={goodsExample} />
  94. <GoodExample />
  95. <Category category={exampleCategory} />
  96. <OrderGood orderGood={exampleOrderGood}/>
  97. <Order order={exampleOrder} />
  98. <OrderList orders={exampleOrderList} />
  99. <OrderGoodsList orderGoods={exampleOrderGoodsList} />
  100. */}
  101. export default App;