detail.js

importReact, { Component } from‘react’ import { createHashHistory } from‘history’ importTestfrom‘./test’ classDetailextendsComponent { render() { return ( <div> <p>{this.props.match.params.id}</p> <buttononClick={() => { createHashHistory().push(‘/home’) }}>点击跳转至首页</button> <Test/> </div> ) } } exportdefaultDetail

test.js

importReact, { Component } from‘react’ import { withRouter } from‘react-router-dom’ classTestextendsComponent { render() { console.log(this.props) return ( <div> Test组件拿到了路由组件传递的信息 </div> ) } } exportdefault withRouter(Test)