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

tanveer ahmad dar picture tanveer ahmad dar · Feb 18, 2019 · Viewed 15.5k times · Source

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

Answer

Remi Sture picture Remi Sture · Feb 18, 2019

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);
    }
}