# Handle Hardware Back button in Rc0

**URL:** <https://forum.ionicframework.com/t/handle-hardware-back-button-in-rc0/65568>\
**Category:** ionic-v3\
**Created:** [October 3, 2016, 2:37pm UTC](https://forum.ionicframework.com/t/handle-hardware-back-button-in-rc0/65568 "2016-10-03T14:37:58Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![almighty99](https://avatars.discourse-cdn.com/v4/letter/a/85e7bf/32.png) [@almighty99](https://forum.ionicframework.com/u/almighty99)\
**Post date:** [October 3, 2016, 2:37pm UTC](https://forum.ionicframework.com/t/handle-hardware-back-button-in-rc0/65568/1 "2016-10-03T14:37:58Z")

</div>

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.
      StatusBar.styleDefault();
       platform.registerBackButtonAction(()=>{
         // How do i handle back button here
       },200)
    });
 }

```

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.

---

<div class="post-metadata">

**Author:** ![Kopertone](https://avatars.discourse-cdn.com/v4/letter/k/90db22/32.png) [@Kopertone](https://forum.ionicframework.com/u/Kopertone)\
**Post date:** [October 3, 2016, 9:51pm UTC](https://forum.ionicframework.com/t/handle-hardware-back-button-in-rc0/65568/2 "2016-10-03T21:51:06Z")

</div>

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')
> this.nav.pop()
> } else if (this.nav.getActive().component.name == "ListPage") {
> this.nav.setRoot(MixesPage)
> } else {
> this.showConfirmExit()
> }
> }, 100);
> 
> ```

---

<div class="post-metadata">

**Author:** ![almighty99](https://avatars.discourse-cdn.com/v4/letter/a/85e7bf/32.png) [@almighty99](https://forum.ionicframework.com/u/almighty99)\
**Post date:** [October 4, 2016, 2:06pm UTC](https://forum.ionicframework.com/t/handle-hardware-back-button-in-rc0/65568/3 "2016-10-04T14:06:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Kopertone](https://avatars.discourse-cdn.com/v4/letter/k/90db22/32.png) [@Kopertone](https://forum.ionicframework.com/u/Kopertone)\
**Post date:** [October 4, 2016, 3:35pm UTC](https://forum.ionicframework.com/t/handle-hardware-back-button-in-rc0/65568/4 "2016-10-04T15:35:18Z")

</div>

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;

---

<div class="post-metadata">

**Author:** ![almighty99](https://avatars.discourse-cdn.com/v4/letter/a/85e7bf/32.png) [@almighty99](https://forum.ionicframework.com/u/almighty99)\
**Post date:** [October 5, 2016, 2:20pm UTC](https://forum.ionicframework.com/t/handle-hardware-back-button-in-rc0/65568/5 "2016-10-05T14:20:53Z")

</div>

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.nav.getActive().component.name 

```

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.

---

<div class="post-metadata">

**Author:** ![burhanyldz](https://avatars.discourse-cdn.com/v4/letter/b/ecc23a/32.png) [@burhanyldz](https://forum.ionicframework.com/u/burhanyldz)\
**Post date:** [October 5, 2016, 2:43pm UTC](https://forum.ionicframework.com/t/handle-hardware-back-button-in-rc0/65568/6 "2016-10-05T14:43:58Z")

</div>

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.
