Guest User

Untitled

a guest
Oct 23rd, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. <Switch>
  2. <Route path="/login" component={ Login } />
  3. <PrivateRoute path="/" component={ Dashboard } exact />
  4. <PrivateRoute path="/members" component={ Members } exact />
  5. <PrivateRoute path="/payments" component={ Bills } exact />
  6. <PrivateRoute path="/gas-stations" component={ GasStations } exact />
  7. <PrivateRoute path="/transactions" component={ Transaction } exact />
  8. <PrivateRoute path="/cms" component={ CMS } />
  9. <PrivateRoute path="/members/:member_id" component={ Member } />
  10. <PrivateRoute path="/gas-stations/:gs" component={ GS } />
  11. <PrivateRoute path="/transactions/:transaction_id" component={ FoundTransaction } />
  12. <PrivateRoute path="/payments/:payment_id" component={ Payment } />
  13. </Switch>
  14.  
  15. import React from 'react';
  16. import { Route, Redirect, withRouter } from 'react-router-dom';
  17. import { connect } from 'react-redux';
  18. import Container from 'components/container';
  19.  
  20. const PrivateRoute = ({ component : Component, authenticated, ...rest }) => {
  21. return (
  22. <Route { ...rest } render={ (props) => (
  23. authenticated === true
  24. ? <Container> // this is the component that wraps the header and the sidebar
  25. <Component { ...props } />
  26. </Container>
  27. : <Redirect to="/login" />
  28. ) } />
  29. )
  30. }
  31.  
  32. const state_to_props = (state, prop) => {
  33. return {
  34. authenticated : state.authenticated
  35. }
  36. }
  37.  
  38. export default connect(state_to_props)(withRouter(PrivateRoute));
  39.  
  40. return (
  41.  
  42. <div>
  43.  
  44. <Header />
  45.  
  46. <SideMenu />
  47.  
  48. <div className="app-content">
  49.  
  50. { props.children }
  51.  
  52. </div>
  53.  
  54. </div>
  55.  
  56. )
  57.  
  58. <li>
  59. <NavLink to="/" exact> <span>Dashboard</span> </NavLink>
  60. </li>
  61. <li>
  62. <NavLink exact to="/members"> <span>Members</span> </NavLink>
  63. </li>
  64. <li>
  65. <NavLink exact to="/gas-stations"> <span>Gas Stations</span> </NavLink>
  66. </li>
  67. <li>
  68. <NavLink exact to="/payments"> <span>Payments</span> </NavLink>
  69. </li>
  70. <li>
  71. <NavLink exact to="/transactions"> <span>Transactions</span> </NavLink>
  72. </li>
  73. <li>
  74. <NavLink exact to="/cms"> <span>CMS</span> </NavLink>
  75. </li>
  76.  
  77. import React, { Component } from "react";
  78. import { Link, withRouter } from 'react-router-dom';
  79.  
  80. class Sidebar extends Component {
  81. constructor(){
  82. ....
  83. }
  84.  
  85. render(){
  86. ....
  87. ....
  88. }
  89. }
  90. export default withRouter(Sidebar);
Add Comment
Please, Sign In to add comment