Get active nav from app.component.ts

Ionic3 i Have Tried the Following Things but it not works
please help me soon

//returns view controller obj 
let view = this.nav.getActive();

//prints out component name as string
console.log(view.component.name);

Read the NavController docs. There’s sample code for this, if I understand your question correctly.

NavController not working in app.component.ts file it ask for No Provider For NavController

//returns view controller obj 
let view = this.nav.getActive();

//prints out component name as string
console.log(view.component.name);

it works only debug mode , ionic cordova run android --prod , it returns only t

You defined nav with @ViewChild the way the docs direct? Because I’ve followed that code and it’s worked for me.

it works only debug mode , ionic cordova run android --prod ,(After minified)
console.log(view.component.name); it returns only t

Try app to get the nav controller…

App is a utility class used in Ionic to get information about various aspects of an app

1 Like

Hello thanks for your reply.
i have tried the following functions from app.
getActiveNav();
console.log(this.app.getActiveNav());

Nav {_config: Config, _elementRef: ElementRef, _renderer: RendererAdapter, _componentName: undefined, parent: null, …}

using element ref i am getting current page name. After --prod mode it only displayt
i have tried all the possibilities to get the current active page name using app provider. no way to get it.

please help me.

Have you tried

this.appCtrl.getRootNav()

I have used this to navigate in an project, but never in production mode.

Or perhaps you can make a provider where you save the page name when the page did load or an other event of the page.

1 Like

Thank you so much Jacktoolsnet for spending time for me

i have tried the second one using provider to save page name… it works fine thank you,


// watch network for a connection if Disconnected
       this.network.onDisconnect().subscribe(() => {
           console.log('network Disconnected!');
           if(this.InternetProvider.current_page != 'NoInternetPage'){
               this.nav.push(NoInternetPage);
               this.InternetProvider.current_page = 'NoInternetPage';
               this.InternetProvider.networkConnected = false;
              
            }
      });
2 Likes

May not be the best but works.

If you have vars that are global to the controller you can access those vars by name, it may identify a class.

let page = this.nav.getActive()
page.instance.nameOfYourVar

If you have a title in the HTML page that belongs to the class that you want to find, you can find that title, it may identify the page as well.

let page = this.nav.getActive()
page._nav._app._title

You can also know which page you are on with.

let page = this.nav.getActive() 
if(page.instance instanceof yourClassNameHereNotString)

I’ll go a step farther and say that any time anybody feels the need to use any of the idioms in your post, it is an indication of a major design flaw.

Hello
I don’t have any error when I use the id instead of name in production.

const page = this._NavController.getActive().id