Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 2.58 KB | None | 0 0
  1.  
  2. import React from 'react'
  3. import CSSTransitionGroup from 'react-transition-group/CSSTransitionGroup'
  4. import {
  5.   BrowserRouter as Router,
  6.   Route,
  7.   Link
  8. } from 'react-router-dom'
  9.  
  10.  
  11. // Each logical "route" has two components, one for
  12. // the sidebar and one for the main area. We want to
  13. // render both of them in different places when the
  14. // path matches the current URL.
  15. const routes = [
  16.   { path: '/',
  17.     exact: true,
  18.     sidebar: () => <div>home!</div>,
  19.     main: () => <h2>Home</h2>
  20.   },
  21.   { path: '/bubblegum',
  22.     sidebar: () => <div>bubblegum!</div>,
  23.     main: () => <h2>Bubblegum</h2>
  24.   },
  25.   { path: '/shoelaces',
  26.     sidebar: () => <div>shoelaces!</div>,
  27.     main: () => <h2>Shoelaces</h2>
  28.   }
  29. ]
  30.  
  31. const SidebarExample = () => (
  32.   <Router>
  33.     <div style={{ display: 'flex' }}>
  34.       <div style={{
  35.         padding: '10px',
  36.         width: '40%',
  37.         background: '#f0f0f0'
  38.       }}>
  39.         <ul style={{ listStyleType: 'none', padding: 0 }}>
  40.           <li><Link to="/">Home</Link></li>
  41.           <li><Link to="/bubblegum">Bubblegum</Link></li>
  42.           <li><Link to="/shoelaces">Shoelaces</Link></li>
  43.         </ul>
  44.           <CSSTransitionGroup
  45.             transitionName="fade"
  46.             transitionEnterTimeout={300}
  47.             transitionLeaveTimeout={300}>
  48.         {routes.map((route, index) => (
  49.           // You can render a <Route> in as many places
  50.           // as you want in your app. It will render along
  51.           // with any other <Route>s that also match the URL.
  52.           // So, a sidebar or breadcrumbs or anything else
  53.           // that requires you to render multiple things
  54.           // in multiple places at the same URL is nothing
  55.           // more than multiple <Route>s.
  56.  
  57.             <Route
  58.               key={index}
  59.               path={route.path}
  60.               exact={route.exact}
  61.               component={route.sidebar}
  62.             />
  63.  
  64.         ))}
  65.            </CSSTransitionGroup>
  66.       </div>
  67.  
  68.       <div style={{ flex: 1, padding: '10px' }}>
  69.                 <CSSTransitionGroup
  70.             transitionName="fade"
  71.             transitionEnterTimeout={300}
  72.             transitionLeaveTimeout={300}>
  73.         {routes.map((route, index) => (
  74.           // Render more <Route>s with the same paths as
  75.           // above, but different components this time.
  76.           <Route
  77.             key={index}
  78.             path={route.path}
  79.             exact={route.exact}
  80.             component={route.main}
  81.           />
  82.         ))}
  83.         </CSSTransitionGroup>
  84.       </div>
  85.     </div>
  86.   </Router>
  87. )
  88.  
  89. export default SidebarExample
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement