|
| 1 | +import React from 'react/addons' |
| 2 | +import { createHistory, useBasename } from 'history' |
| 3 | +import { Router, Route, Link } from 'react-router' |
| 4 | + |
| 5 | +require('./app.css') |
| 6 | + |
| 7 | +const history = useBasename(createHistory)({ |
| 8 | + basename: '/breadcrumbs' |
| 9 | +}) |
| 10 | + |
| 11 | +class App extends React.Component { |
| 12 | + static title = 'Home'; |
| 13 | + static path = '/'; |
| 14 | + |
| 15 | + render() { |
| 16 | + const depth = this.props.routes.length |
| 17 | + |
| 18 | + return ( |
| 19 | + <div> |
| 20 | + <aside> |
| 21 | + <ul> |
| 22 | + <li><Link to={Products.path}>Products</Link></li> |
| 23 | + <li><Link to={Orders.path}>Orders</Link></li> |
| 24 | + </ul> |
| 25 | + </aside> |
| 26 | + <main> |
| 27 | + <ul className="breadcrumbs-list"> |
| 28 | + {this.props.routes.map((item, index) => |
| 29 | + <li key={index}> |
| 30 | + <Link |
| 31 | + onlyActiveOnIndex={true} |
| 32 | + activeClassName="breadcrumb-active" |
| 33 | + to={item.path || ''}> |
| 34 | + {item.component.title} |
| 35 | + </Link> |
| 36 | + {(index + 1) < depth && '\u2192'} |
| 37 | + </li> |
| 38 | + )} |
| 39 | + </ul> |
| 40 | + {this.props.children} |
| 41 | + </main> |
| 42 | + </div> |
| 43 | + ) |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +class Products extends React.Component { |
| 48 | + static title = 'Products'; |
| 49 | + static path = '/products'; |
| 50 | + |
| 51 | + render() { |
| 52 | + return ( |
| 53 | + <div className="Page"> |
| 54 | + <h1>Products</h1> |
| 55 | + </div> |
| 56 | + ) |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | +class Orders extends React.Component { |
| 61 | + static title = 'Orders'; |
| 62 | + static path = '/orders'; |
| 63 | + |
| 64 | + render() { |
| 65 | + return ( |
| 66 | + <div className="Page"> |
| 67 | + <h1>Orders</h1> |
| 68 | + </div> |
| 69 | + ) |
| 70 | + } |
| 71 | +} |
| 72 | + |
| 73 | +React.render(( |
| 74 | + <Router history={history}> |
| 75 | + <Route path={App.path} component={App}> |
| 76 | + <Route path={Products.path} component={Products} /> |
| 77 | + <Route path={Orders.path} component={Orders} /> |
| 78 | + </Route> |
| 79 | + </Router> |
| 80 | +), document.getElementById('example')) |
0 commit comments