react-router go back a page how do you configure history?

前端 未结 21 1294
说谎
说谎 2020-11-30 18:30

Can anyone please tell me how I can go back to the previous page rather than a specific route?

When using this code:

var BackButton = React.createCla         


        
21条回答
  •  感动是毒
    2020-11-30 18:51

    Call the following component like so:

    
    

    And here is the component:

    import React, { Component } from 'react'
    import PropTypes from 'prop-types'
    class BackButton extends Component {
      constructor() {
        super(...arguments)
    
        this.goBack = this.goBack.bind(this)
      }
    
      render() {
        return (
          
        )
      }
    
      goBack() {
        this.props.history.goBack()
      }
    }
    
    BackButton.propTypes = {
      history: PropTypes.object,
    }
    
    export default BackButton
    

    I'm using:

    "react": "15.6.1"
    "react-router": "4.2.0"
    

提交回复
热议问题