Search code examples
javascriptbrowser-history

Back button fires as soon as page loads


Here is the code for the back button I'm trying to include at the top of my page:

<a onClick={this.goBack()}>Go back</a>

And here is the helper function goBack():

  goBack(){
    return history.go(-1);
  }

I've also tried this, which produces the same result:

<a href={this.goBack()}>Go back</a>

I'm new to the history method, so any clarification would be much appreciated! Thanks


Solution

  • <a href="#" onclick="window.history.back()">Go back</a>