My Blog


ionic 2 and Angular 2 Detect Browser Back Button Functionality

Posted: November 24, 2021. | By: Admin

Add Below Code at  app.component.ts 
import { IonicApp, App, MenuController } from 'ionic-angular';

@Component ({...})
export class MyWebApp {

  constructor (private _app: App, private _ionicApp: IonicApp, private _menu: MenuController) {

    platform.ready().then(() => {
      // Do your thing...
      this.setupBackButtonBehavior ();

  private setupBackButtonBehavior () {

    // If on web version (browser)
    if (window.location.protocol !== "file:") {

      // Register browser back button action(s)
      window.onpopstate = (evt) => {

        // Close menu if open
        if (this._menu.isOpen()) {
          this._menu.close ();

        // Close any active modals or overlays
        let activePortal = this._ionicApp._loadingPortal.getActive() ||
          this._ionicApp._modalPortal.getActive() ||
          this._ionicApp._toastPortal.getActive() ||

        if (activePortal) {

        // Navigate back
        if (this._app.getRootNav().canGoBack()) this._app.getRootNav().pop();


      // Fake browser history on each view enter
      this._app.viewDidEnter.subscribe((app) => {
        history.pushState (null, null, "");




Aapthi Technologies,Hyderabad offers a complete range of web solutions including web designing, developing, web hosting, Internet marketing and many more. With our electrifying presence, we have swirled the scenario of web solutions. We consistently invigorate our skill-set and tech-expertise and work with a high-level of integrity. Our keen-eye on emerging trends of online business as well as technical spheres has empowered us to render the most innovative solutions. Persistent development is the key drive of Aapthi Technologies, be it in terms of infrastructure, skill-set or technology. Team Aapthi Technologies, is fully committed to render back hundred percent value for the money paid by client.

Social Links

Our Bunker

Plot No -596, Near Reliance Fresh,
Vivekananda nagar colony, Kukatpally,
Hyderabad - 500072, India.