Repos.js 962 B

123456789101112131415161718192021222324252627282930313233343536
  1. import React from 'react'
  2. import NavLink from './NavLink'
  3. export default React.createClass({
  4. contextTypes: {
  5. router: React.PropTypes.object
  6. },
  7. handleSubmit(event) {
  8. event.preventDefault()
  9. const userName = event.target.elements[0].value
  10. const repo = event.target.elements[1].value
  11. const path = `/repos/${userName}/${repo}`
  12. this.context.router.push(path)
  13. },
  14. render() {
  15. return (
  16. <div>
  17. <h2>Repos</h2>
  18. <ul>
  19. <li><NavLink to="/repos/reactjs/react-router">React Router</NavLink></li>
  20. <li><NavLink to="/repos/facebook/react">React</NavLink></li>
  21. <li>
  22. <form onSubmit={this.handleSubmit}>
  23. <input type="text" placeholder="userName"/> / {' '}
  24. <input type="text" placeholder="repo"/>{' '}
  25. <button type="submit">Go</button>
  26. </form>
  27. </li>
  28. </ul>
  29. {this.props.children}
  30. </div>
  31. )
  32. }
  33. })