1.页面有有个按钮 ,点击这个按钮跳转页面
官方文档说:使用withRouter解决
=====================
import React from 'react'
import PropTypes from 'prop-types'
import { withRouter } from 'react-router'
class ShowTheLocation extends React.Component {
static propTypes = {
match: PropTypes.object.isRequired,
location: PropTypes.object.isRequired,
history: PropTypes.object.isRequired
}
render() {
const { match, location, history } = this.props
return (
<div>You are now at {location.pathname}</div>
)
}
}
const ShowTheLocationWithRouter = withRouter(ShowTheLocation)
=====================
在实际应用的时候 这段代码怎么用呢?
withRouter 是一个高阶组件? 返回一个ShowTheLocationWithRouter函数? 那这个函数怎么用到跳转呢?
const { match, location, history } = this.props // 这行是什么意思呢?
使用 history.push('/xxx') 这样吗
现在有一个button 组件 怎么在这个组件上添加事件进行路由跳转呢