# How to get current active Component in RC0?

**URL:** <https://forum.ionicframework.com/t/how-to-get-current-active-component-in-rc0/67468>\
**Category:** ionic-v3\
**Created:** [October 19, 2016, 11:54am UTC](https://forum.ionicframework.com/t/how-to-get-current-active-component-in-rc0/67468 "2016-10-19T11:54:37Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sumeet123](https://avatars.discourse-cdn.com/v4/letter/s/839c29/32.png) [@Sumeet123](https://forum.ionicframework.com/u/Sumeet123)\
**Post date:** [October 19, 2016, 11:54am UTC](https://forum.ionicframework.com/t/how-to-get-current-active-component-in-rc0/67468/1 "2016-10-19T11:54:37Z")

</div>

Till beta , this use to work for me

`if(view.componentType.name == 'HomePage')`

In RC0 , due to minification name **returns ‘t’**

How do i get the component name ?

Thanks

---

<div class="post-metadata">

**Author:** ![bengtler](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/bengtler/32/98565_2.png) [@bengtler](https://forum.ionicframework.com/u/bengtler)\
**Post date:** [October 19, 2016, 11:59am UTC](https://forum.ionicframework.com/t/how-to-get-current-active-component-in-rc0/67468/2 "2016-10-19T11:59:08Z")

</div>

Why do you need the current component name Oo? In which use case?

---

<div class="post-metadata">

**Author:** ![Sumeet123](https://avatars.discourse-cdn.com/v4/letter/s/839c29/32.png) [@Sumeet123](https://forum.ionicframework.com/u/Sumeet123)\
**Post date:** [October 19, 2016, 12:02pm UTC](https://forum.ionicframework.com/t/how-to-get-current-active-component-in-rc0/67468/3 "2016-10-19T12:02:33Z")

</div>

I override the back button behaviour in my app.

In which , if user presses back button on any page , user should go on first tab. If user is on first tab , user is asked to press back button twice to exit.

---

<div class="post-metadata">

**Author:** ![bengtler](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/bengtler/32/98565_2.png) [@bengtler](https://forum.ionicframework.com/u/bengtler)\
**Post date:** [October 19, 2016, 12:06pm UTC](https://forum.ionicframework.com/t/how-to-get-current-active-component-in-rc0/67468/4 "2016-10-19T12:06:32Z")

</div>

okay then as workaround:

> **[Ionic Framework](https://ionicframework.com/docs/api/navigation/NavController/)**
>
> Ionic is the app platform for web developers. Build amazing mobile, web, and desktop apps all with one shared code base and open web standards

Get the navcontroller instance --\> retrieve the first view in history stack  
Check if this is the active one:

> **[Ionic Framework](https://ionicframework.com/docs/api/navigation/NavController/)**
>
> Ionic is the app platform for web developers. Build amazing mobile, web, and desktop apps all with one shared code base and open web standards

if so --\> ask to exit, else goto first tab  
No need to check on explicit name strings

---

<div class="post-metadata">

**Author:** ![Sumeet123](https://avatars.discourse-cdn.com/v4/letter/s/839c29/32.png) [@Sumeet123](https://forum.ionicframework.com/u/Sumeet123)\
**Post date:** [October 19, 2016, 12:12pm UTC](https://forum.ionicframework.com/t/how-to-get-current-active-component-in-rc0/67468/5 "2016-10-19T12:12:37Z")

</div>

I will revert once I try it. But , overriding back button also breaks popver navigation.

Like if popover is open , and user hits back then popover won’t close instead it will navigate and popover still remains open.

For this , I had a weird hack, by checking state

```
     if(child['_views'][0].componentType.name == 'ContactPage' && child['_views'][0].state!=1){
                    // this assumed popover was open
                     }else{
                         t.select(0);
                       }
```

---

<div class="post-metadata">

**Author:** ![Sumeet123](https://avatars.discourse-cdn.com/v4/letter/s/839c29/32.png) [@Sumeet123](https://forum.ionicframework.com/u/Sumeet123)\
**Post date:** [October 19, 2016, 12:38pm UTC](https://forum.ionicframework.com/t/how-to-get-current-active-component-in-rc0/67468/6 "2016-10-19T12:38:05Z")

</div>

As you said I did this ,

```
let firstView : any;
firstView = this.nav.first();
if(this.nav.isActive(firstView)){
     console.log('first tab active');
  }else{
      console.log('Go to first tab');
}

```

And the above returns `'first tab active'` on every tab.

---

<div class="post-metadata">

**Author:** ![Duveral](https://avatars.discourse-cdn.com/v4/letter/d/c57346/32.png) [@Duveral](https://forum.ionicframework.com/u/Duveral)\
**Post date:** [June 6, 2017, 9:50am UTC](https://forum.ionicframework.com/t/how-to-get-current-active-component-in-rc0/67468/7 "2017-06-06T09:50:21Z")

</div>

I don’t understand why there is no a function to retrieve the view name.

I’m setting a custom id inside the view I want to check to compare, but we have to dig into long paths to even access the view variables.

So, if I want to access the variable ‘idView’ from the activeView from anywhere, like app.component.ts

`this.nav.getActive().getNav()['_views'][0].instance.idView`

Ionic 3.3.0

---

<div class="post-metadata">

**Author:** ![rapropos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rapropos/32/100227_2.png) [@rapropos](https://forum.ionicframework.com/u/rapropos)\
**Post date:** [June 6, 2017, 8:54pm UTC](https://forum.ionicframework.com/t/how-to-get-current-active-component-in-rc0/67468/8 "2017-06-06T20:54:18Z")

</div>

IMHO, any design that needs this functionality is broken.

Pages should be self-contained. If something has to change (like back button behavior) when a page is active, add and remove listeners using the page’s lifecycle events. Don’t centralize all this in a massive nerve center. The code becomes unreadable and untestable because you have action-at-a-distance all over the app.

---

<div class="post-metadata">

**Author:** ![Duveral](https://avatars.discourse-cdn.com/v4/letter/d/c57346/32.png) [@Duveral](https://forum.ionicframework.com/u/Duveral)\
**Post date:** [June 7, 2017, 6:58am UTC](https://forum.ionicframework.com/t/how-to-get-current-active-component-in-rc0/67468/9 "2017-06-07T06:58:51Z")

</div>

Found a way to compare the active view without using name!

_Example: We want to know, from anywhere, if the active view is the page ‘gallery’._

```auto
import { GalleryPage } from '../gallery/gallery';

if (this.nav.getActive().component == GalleryPage){ dosomething}

```
