React-Router ---withRouter

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
posted @ 2018-10-15 16:36  徐肥美  阅读(471)  评论(0编辑  收藏  举报