Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

3
  • 2
    just unfortunate that the answer was already given 5 years earlier, and even misses the part where you define location in the constructor Commented May 16, 2022 at 11:41
  • Yes, don't forget to define in your constructor() the: private location: Location Commented Jun 3, 2022 at 17:55
  • 1
    As noted above for one of the proposed solutions, beware that there's an edge case with this scenario such that if user opens a new tab there won't be an entry in the history to go back to. This can throw user out of the Angular application as well as introduce security issues as there's no API for directly inspecting the browser history. Commented Oct 25, 2022 at 13:22