
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
angular-disable-browser-back-button
Advanced tools
Angular Module to disable Browser back button
This Angular module generated using @angular/cli version 16.0.0. Module developed to help Angular developers to disable the browser back button.
Copy the following command to your command line or terminal to install the package.
npm install --save angular-disable-browser-back-button
Import the BackButtonDisableModule to your project app.module.ts file and add it to imports list
import { NgModule } from '@angular/core';
import { BackButtonDisableModule } from 'angular-disable-browser-back-button';
@NgModule({
...
imports: [
...
BackButtonDisableModule.forRoot()
],
...
})
export class AppModule {}
Module will prevent browser backspace navigation and return user to the same page by preserving all states.
The issue of the prevented backspace navigation is that it will move user to the webpage top. So you can use module configuration to preserve scroll position as well.
import { NgModule } from '@angular/core';
import { BackButtonDisableModule } from 'angular-disable-browser-back-button';
@NgModule({
...
imports: [
...
BackButtonDisableModule.forRoot({
preserveScroll: true
})
],
...
})
export class AppModule {}
Run your application by typing the ng serve or ng build commands in your command line or terminal, and see the results: The browser back button will be disabled for whole the application.
Note: Module doesn't work per-module and isn't tested with Angular Universal.
Note: Since version 75 Chrome requires at least one user interction to trigger popstate event on back button click. More about Chrome issue you can read in the discussion of chrome issue about user interactions.
FAQs
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.