Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how we can get the current page from app.component in ionic 4?

Tags:

angular

ionic4

i am trying to get current page instance in app.component in ionic 4.

in ionic 3 i can do it like this

this.nav.getActive().instance

like image 775
tanveer ahmad dar Avatar asked Feb 18 '19 11:02

tanveer ahmad dar


People also ask

How do I navigate one page to another page in ionic 4?

Ionic has a similar concept where you can only view the page on top of the navigation stack. If you want to navigate to another page, you need to do one of these two actions: Push: Push the page on the stack. It means putting the element at the top.

How do you navigate to another page in ionic?

Navigation in Ionic works like a simple stack, where we push new pages onto the top of the stack, which takes us forwards in the app and shows a back button. To go backwards, we pop the top page off.

How do I change the root page in ionic 4?

In Ionic 4 with Angular routing, there is no root page to be defined. Because Ionic 4 relies on Angular's router, the NavController has been changed to reflect this new reality, and for an Angular application there is no such a thing like "root" route.


1 Answers

You can access the url from the Router.

import { OnInit } from '@angular/core';
import { Router } from '@angular/router';

export class YourPage implements OnInit {
   constructor(private router: Router) {}

   ngOnInit() {
        console.log('this.router.url', this.router.url);
    }
}
like image 190
Remi Sture Avatar answered Sep 23 '22 18:09

Remi Sture