Check history previous location before goBack() react router v4

While navigating though the Link component or even though history.push, you could pass the current location to another Route component

like

<Link to={{pathname: '/graph/1', state: { from: this.props.location.pathname }}} />

or

history.push({
  pathname: '/graph/1',
  state: { 
      from: this.props.location.pathname
  }
})

and then you could just get this location in your Component like this.props.location.state && this.props.location.state.from and then decide whether you wan’t to goBack or not

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)