|
| 1 | +import {createElement as h} from 'react'; |
| 2 | +import {LocationSensor} from '../../LocationSensor'; |
| 3 | +import {Router, Route} from '..'; |
| 4 | + |
| 5 | +const StoryRouteExample = () => ( |
| 6 | + <Router> |
| 7 | + <div> |
| 8 | + <ul> |
| 9 | + <li onClick={() => history.pushState(null, '', '/home.html')}>Home</li> |
| 10 | + <li onClick={() => history.pushState(null, '', '/home/intro.html')}>Home / Intro</li> |
| 11 | + <li onClick={() => history.pushState(null, '', '/home/more.html')}>Home / More</li> |
| 12 | + <li onClick={() => history.pushState(null, '', '/page.html')}>Page</li> |
| 13 | + <li onClick={() => history.pushState(null, '', '/404.html')}>404</li> |
| 14 | + </ul> |
| 15 | + |
| 16 | + <Route match='/home'>{() => |
| 17 | + <div> |
| 18 | + <div>HOME</div> |
| 19 | + <Route match='/intro' children={<div>INTRO</div>} /> |
| 20 | + <Route children={<div>HOME/404</div>} /> |
| 21 | + </div> |
| 22 | + }</Route> |
| 23 | + <Route match={/^\/page\.html/} children={<div>PAGE</div>} /> |
| 24 | + <Route children={<div>404</div>} /> |
| 25 | + |
| 26 | + <br /> |
| 27 | + <hr /> |
| 28 | + |
| 29 | + <LocationSensor>{(state) => |
| 30 | + <pre style={{fontFamily: 'monospace'}}> |
| 31 | + {JSON.stringify(state, null, 4)} |
| 32 | + </pre> |
| 33 | + }</LocationSensor> |
| 34 | + |
| 35 | + <br /> |
| 36 | + <hr /> |
| 37 | + |
| 38 | + <pre style={{fontFamily: 'monospace'}}>{` |
| 39 | +<Route match='/home'>{() => |
| 40 | + <div> |
| 41 | + <div>HOME</div> |
| 42 | + <Route match='/intro' children={<div>INTRO</div>} /> |
| 43 | + <Route children={<div>HOME/404</div>} /> |
| 44 | + </div> |
| 45 | +}</Route> |
| 46 | +<Route match={/^\/page\.html/} children={<div>PAGE</div>} /> |
| 47 | +<Route children={<div>404</div>} /> |
| 48 | + `}</pre> |
| 49 | + </div> |
| 50 | + </Router> |
| 51 | +); |
| 52 | + |
| 53 | +export default StoryRouteExample; |
0 commit comments