react 中 怎样正确使用histroy.push()改变路由?

react 中 怎样正确使用histroy.push()改变路由?
import { withRouter } from 'react-router-dom'


class
MyComponent extends React.Component { ... myFunction() { this.props.history.push("/dashboard"); } ... } export default withRouter(MyComponent);
 

We can also bring the data from the current page to our destination page using the second argument of this function:

class MyComponent extends React.Component { 
  ... 
  myFunction() { 
    this.props.history.push("/dashboard", { state: 'sample data'}); 
  } 
  ... 
} 

export default withRouter(MyComponent);
 

Note: You can only use this.props.history.push() function inside the component page that already listed on your project route, or simply use the withRouter() HOC if the component is not available in the route list.

设置