Link
Components are used for normal user-click jumps, but sometimes the form jumps, click button jumps, and so on. How do these situations router with react?
Here is a form.
<form onsubmit={this.handlesubmit}><inputType=The text"Placeholder="UserName"/><inputType=The text "placeholder= "Repo" /> < Button type= "Submit" >go</button > </form>
The first method is to use thebrowserHistory.push
Import{Browserhistory} from' React-router '// ...Handlesubmit(Event){Event.Preventdefault() Const USERNAME= Event. Target. elements[0].value const repo = Event.target.elements [1].value const path = ' /repos/${username}/${repo} ' Browserhistory. push (Path}
The second method is to use the context
object.
Export Default React.Createclass({Ask for ' router ' from context Contexttypes: {router: React. Proptypes. Object }, handlesubmit(event) { //... this. Context. router . Push(Path) },})
React-router JS Control routing jump (reprint)