Handle Hardware Back button in Rc0

How do Set app level back button action… What I have is this

  constructor(platform: Platform) {
    platform.ready().then(() => {
      // Okay, so the platform is ready and our plugins are available.
      // Here you can do any higher level native things you might need.
         // How do i handle back button here

I want to achieve is that when the user is at home i want to exit otherwise go to home.

I am unable to figure out how can I check for active view name.

Here is how I do it in mine

  this.platform.registerBackButtonAction(() => {
    console.log('back button pressed')
    if (this.nav.canGoBack()) {
      console.log('nav can go back')
    } else if (this.nav.getActive().component.name == "ListPage") {
    } else {
  }, 100);
1 Like

yes i tried it…when I inject the NavController into the constructor of the app.component.ts i get an exception

EXCEPTION: No provider for t!

Can you specify where are you registering the back button handler? As i mentioned doing it in the app.component.ts gives an exception

In the app.component.ts is where I have it.

You don’t use NavControlelr in the app.component, instead you just use Nav.

import {Platform, MenuController, Nav, AlertController, ModalController} from ‘ionic-angular’;
Also you add @ViewChild(Nav) nav: Nav;

I am using the tabs template and now i have the Nav injected in the constructor.
I am trying to get the name of the view as follows


This returns the letter t and not the name of the component.

This does not happen in the browser. In the browser proper name value is returned but not on device.

Yes, I have the same problem in Rc0. It used to be the full name of the component, now they are shortened.
Dont know any other ways to identify the active page.