Advertisement
Guest User

Untitled

a guest
Apr 1st, 2020
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. import React from 'react';
  2. import { BrowserRouter, Route, Switch, Redirect } from 'react-router-dom';
  3. import Cookies from 'universal-cookie';
  4.  
  5. import Home from './Home';
  6. import Library from './Library';
  7. import Layout from './Layout';
  8. import MoviePlayer from './MoviePlayer';
  9. import Starred from './Starred';
  10. import Saw from './Saw';
  11. import Signup from './Signup';
  12. import Login from './Login';
  13. import Profile from './Profile';
  14. import Fpassword from './Fpassword';
  15. import ResetPassword from './ResetPassword';
  16. import OtherProfile from './OtherProfile';
  17.  
  18. const cookies = new Cookies();
  19.  
  20. const SecureRoute = ({ path, component }) => {
  21. if (cookies.get('authtoken')) {
  22. return (
  23. <Route exact path={path} component={component} />
  24. );
  25. }
  26. return (
  27. <Redirect to="/" />
  28. );
  29. };
  30.  
  31. const AuthRoute = ({ path, component }) => {
  32. if (cookies.get('authtoken')) {
  33. return (
  34. <Redirect to="/library" />
  35. );
  36. }
  37. return (
  38. <Route exact path={path} component={component} />
  39. );
  40. };
  41.  
  42. const App = () => (
  43. <BrowserRouter>
  44. <Switch>
  45. <AuthRoute exact path="/" component={Home} />
  46.  
  47. <AuthRoute exact path="/Signup" component={Signup} />
  48. <AuthRoute exact path="/Login" component={Login} />
  49. <AuthRoute exact path="/Fpassword" component={Fpassword} />
  50. <AuthRoute exact path="/ResetPassword" component={ResetPassword} />
  51.  
  52. <Layout>
  53. <SecureRoute exact path="/library" component={Library} />
  54. <SecureRoute exact path="/library/:tabsValue" component={Library} />
  55. <SecureRoute exact path="/movie/:movieId" component={MoviePlayer} />
  56. <SecureRoute exact path="/starred" component={Starred} />
  57. <SecureRoute exact path="/saw" component={Saw} />
  58. <SecureRoute exact path="/profile" component={Profile} />
  59. <SecureRoute exact path="/otherprofile/:userName" component={OtherProfile} />
  60. </Layout>
  61. </Switch>
  62. </BrowserRouter>
  63. );
  64.  
  65. export default App;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement