react router 4 方法函数中使用 history

参考文档: react router 文档

import React from "react"
import { withRouter } from "react-router-dom"

class ShowTheLocation extends React.Component {

  toOtherRoute = () => {
    const urlObj = {
      pathname: 'url/url',
      state: {
        data: 'data'
      }
    }
    this.props.history.push(urlObj)
  }

  render() {
    return (
      
hello word
跳转路由
) } } ShowTheLocation = withRouter(ShowTheLocation)

在跳转过去的组件接收参数:

const { data } = this.props.location.state

总结: 多看官方文档 QAQ

你可能感兴趣的:(React)