Subscribe to Navbar back button?


#1

Does anyone know if there’s a way to hook into the navbar’s back button for a specific view? I’d like to subscribe to the interaction and fire off an action in redux to update the application state.

I tried page events, but I was getting some unexpected behavior & it wasn’t clear how I could identify the back button action


#2

Interesting question. No clue. But if the ionic doc does not give pointers I would inspect the element and try to go under the hood and attach an eventlistener to the dom element (getElement stuff and the addEventlistnerer)

Not a proven way, but my thoughts


#3

I think I figured it out, looks like ionViewWillUnload() is triggered on a pop, but not a push


#4

As to getting the back-button, this may be of help

import { IonicPage, NavController, NavParams, Navbar } from 'ionic-angular'
import { ViewChild, ElementRef } from '@angular/core';

export class NavButtonPage {
@ViewChild(Navbar) navBar: Navbar;
    constructor(){

   }
 
ionViewDidLoad(): void {
   this.navbar.backButtonClick = () => {
   console.log('clicked');
   this.navCtrl.pop()
		}
   }

}