This repository was archived by the owner on Jul 19, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed
lessons/12-navigating/modules Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change 11import React from 'react'
22import NavLink from './NavLink'
3+ import { browserHistory } from 'react-router'
34
45export default React . createClass ( {
6+ // ask for `router` from context
7+ contextTypes : {
8+ router : React . PropTypes . object
9+ } ,
10+
11+ handleSubmit ( event ) {
12+ event . preventDefault ( ) ;
13+ const userName = event . target . elements [ 0 ] . value ;
14+ const repo = event . target . elements [ 1 ] . value ;
15+ const path = `/repos/${ userName } /${ repo } ` ;
16+ this . context . router . push ( path ) ; // 将form里的内容形成链接交给route去渲染。也就是只要有链接,就可以相应的渲染。
17+ console . log ( path ) ;
18+ } ,
19+
520 render ( ) {
621 return (
722 < div >
823 < h2 > Repos</ h2 >
924 < ul >
1025 < li > < NavLink to = "/repos/reactjs/react-router" > React Router</ NavLink > </ li >
1126 < li > < NavLink to = "/repos/facebook/react" > React</ NavLink > </ li >
27+ { /* Add this form */ }
28+ < li >
29+ < form onSubmit = { this . handleSubmit } >
30+ < input type = "text" placeholder = "userName" /> / { ' ' }
31+ < input type = "text" placeholder = "repo" /> { ' ' }
32+ < button type = "submit" > Go</ button >
33+ </ form >
34+ </ li >
1235 </ ul >
1336 { this . props . children }
1437 </ div >
You can’t perform that action at this time.
0 commit comments