Skip to content

Instantly share code, notes, and snippets.

@robozavri
Last active September 10, 2020 08:07
Show Gist options
  • Save robozavri/3f6496383f065d6cb980743ce21bc5a3 to your computer and use it in GitHub Desktop.
Save robozavri/3f6496383f065d6cb980743ce21bc5a3 to your computer and use it in GitHub Desktop.
#angular disable browser back button popstate
import { LocationStrategy } from '@angular/common';
/ Inject LocationStrategy Service into your component
constructor(
private locationStrategy: LocationStrategy
) { }
// Define a function to handle back button and use anywhere
preventBackButton() {
history.pushState(null, null, location.href);
this.locationStrategy.onPopState(() => {
history.pushState(null, null, location.href);
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment