In many cases, we also need to pass parameters in the page jump at the same time. In react-router-dom, there are two ways to pass parameters
* the url parameter
{/ * Home. Js * /} < button onClick = {() = > {this. Props. History. Push ('/detail / 88 ')}} > details page < / button > {/ * router. Js */} <Route exact path="/detail/:id" component={detail}></Route> {/* detail.js */} componentDidMount(){ console.log(this.props.match.params); }Copy the code
* Pass parameters implicitly
{/* Home.js */} <button onClick={()=>{this.props.history.push({ pathname: '/detail', state: { id: {/* router.js */} <Route exact path="/detail" component={detail}></Route> {/* detail.js */} componentDidMount(){ console.log(this.props.history.location.state); }Copy the code