Routs.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import {Router, Route, Redirect, Switch} from 'react-router-dom';
  2. import { history } from '../App';
  3. import {LoginForm} from './authorization';
  4. import {CRegisterForm} from './authRegistration';
  5. import { store } from '../store/store';
  6. import { ToastNotify } from './Toast';
  7. import { CUserPage } from '../pages/userPage';
  8. import {CPlaylistById} from './playlistById';
  9. import {СNowPlayingPlayer} from './playing'
  10. import { CEditProfile } from './EditProfile';
  11. import { Header } from './header';
  12. import { CArtistPage } from '../pages/artistPage';
  13. import { CAlbumPage } from '../pages/albumPage';
  14. import { CSearchPage } from '../pages/searchPage';
  15. import { AllPlaylistsPage } from '../pages/allPlaylistsPage';
  16. export const Main = ({auth}) =>
  17. <main className='bg-dark text-white main' >
  18. <Router history = {history}>
  19. <Content className=''>
  20. <div>
  21. <Switch>
  22. {auth && <Redirect from='/login' to={'/user'} exact />}
  23. {auth && <Redirect from='/register' to={'/user'} exact />}
  24. {!auth && <Redirect from='/user' to={'/login'} exact />}
  25. {!auth && <Redirect from='/editprofile' to={'/login'} exact />}
  26. {!auth && <Redirect from='/allplaylists' to={'/login'} exact />}
  27. {!auth && <Redirect from='/playlist' to={'/login'} exact />}
  28. {!auth && <Redirect from='/artists' to={'/login'} exact />}
  29. {!auth && <Redirect from='/albums' to={'/login'} exact />}
  30. {!auth && <Redirect from='/search' to={'/login'} exact />}
  31. <Route path={'/login'} component={LoginForm} />
  32. <Route path={'/register'} component={CRegisterForm}/>
  33. <Route path={'/editprofile'} component={CEditProfile}/>
  34. <Route path={'/allplaylists'} component={AllPlaylistsPage}/>
  35. <Route path={'/playlist'} component={CPlaylistById} />
  36. <Route path={'/user'} component={CUserPage} />
  37. <Route path={'/artists'} component={CArtistPage} />
  38. <Route path={'/albums'} component={CAlbumPage} />
  39. <Route path={'/search'} component={CSearchPage} />
  40. <Route exact path="/">{auth ? <Redirect to="/user"/> : <Redirect to="/login" /> }</Route>
  41. </Switch>
  42. </div>
  43. </Content>
  44. </Router>
  45. </main>
  46. const Content = ({children}) =>
  47. <>
  48. {store.getState().auth?.token && <Header/>}
  49. <section className='d-flex justify-content-center container-fluid pt-3'>
  50. <ToastNotify/>
  51. <div className={store.getState().auth?.token ? 'col-7 pe-3' : 'col-12 pe-3'}>
  52. {children}
  53. </div>
  54. {store.getState().auth?.token && <СNowPlayingPlayer className='col-5'/>}
  55. </section>
  56. </>