Routers.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import React from "react";
  2. import { BrowserRouter as Router, Route, Switch, Redirect } from "react-router-dom";
  3. import * as createHistory from "history";
  4. import { connect } from "react-redux";
  5. import { actionFullLogin } from "../actions/actionFullLogin";
  6. import { actionFullRegister } from "../actions/actionFullRegister";
  7. import { LoginForm } from "../pages/LoginForm";
  8. import { FormReg } from "../pages/FormReg";
  9. import { Main } from "../pages/Main";
  10. import { Home } from "../pages/WorkPage";
  11. import { Cabinet } from "../pages/Cabinet";
  12. import ConnectFormSearch from "../pages/Search";
  13. import CProjects from "../pages/Projects";
  14. import ConnectedProject from "../pages/Project";
  15. const history = createHistory.createBrowserHistory();
  16. const ConnectLoginForm = connect(null, {onLogin:actionFullLogin}) (LoginForm);
  17. const ConnectFormReg = connect(null, {FormReg:actionFullRegister}) (FormReg);
  18. const Routs = ({token}) => {
  19. return (
  20. <div className="App">
  21. <Router history = {history}>
  22. {token && <Switch>
  23. <Redirect from="/login" to="/work" />
  24. <Redirect from="/reg" to="/work" />
  25. <Route exact path='/work' component={Home} />
  26. <Route path='/cabinet' component={Cabinet}/>
  27. <Route path='/projects' component={CProjects}/>
  28. <Route path='/project' component={ConnectedProject}/>
  29. <Route path='/search' component={ConnectFormSearch}/>
  30. </Switch>}
  31. {!token && <Switch>
  32. <Route path='/login' component={ConnectLoginForm}/>
  33. <Route path='/reg' component={ConnectFormReg}/>
  34. <Route path='/' component={Main}/>
  35. </Switch>}
  36. </Router>
  37. </div>
  38. )
  39. }
  40. const ConnectedRouts = connect(state =>({token: state.a.token}), null)(Routs);
  41. export default ConnectedRouts;