Search code examples
polymerlit-elementlit-html

How to navigate to the previous route on paper-button click?


I have used lit-element-router and was trying to navigate to the previous route on button click.

<paper-button @click="${() => this.goBack()}">Go back</paper-button>

goBack() {
  this.navigate();
}

Question: How to get the previous route path on clicking the button?

Any solution would be great!


Solution

  • If you look at the source then you can see that the navigate function uses window.history under the hood.

    This will work:

    <paper-button @click="${() => window.history.back()}">Go Back</paper-button>