import React from 'react' import { withRouter } from 'react-router' const Hello = (props) => { return ( <div><button onClick={ () => props.history.push('/about') }>Hello</button></div> ) } const WithRouterHello = withRouter(Hello);//也可以用es6的语法@ const Home = (props) => { return ( <div> <button onClick={ () => props.history.push('/about') }>click me</button> <p>Welcome Home</p> <WithRouterHello /> </div> ) } export default Home
转载于:https://www.cnblogs.com/xufeimei/p/9791797.html