App.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import './App.scss';
  2. import { Router, Route, Switch, Redirect } from 'react-router-dom';
  3. import createHistory from "history/createBrowserHistory";
  4. import { connect, Provider } from 'react-redux';
  5. import { store } from './redux/redux-store';
  6. import { Authorization } from './pages/Authorization';
  7. import { Content } from './pages/Content';
  8. export const history = createHistory()
  9. const AppContent = ({ isToken }) =>
  10. <Router history={history}>
  11. {!isToken
  12. ?
  13. <Switch>
  14. <Route path='/login' component={Authorization} />
  15. <Redirect from='/*' to='/login' />
  16. </Switch>
  17. :
  18. <Switch>
  19. <Route path='/' component={Content} exact />
  20. {/* <Redirect from='/*' to='/' /> */}
  21. </Switch>
  22. }
  23. </Router >
  24. const CAppContent = connect(state => ({ isToken: state.auth?.token }))(AppContent)
  25. store.subscribe(() => console.log(store.getState()))
  26. function App() {
  27. return (
  28. <Provider store={store}>
  29. <CAppContent />
  30. </Provider>
  31. )
  32. }
  33. export default App;