我们如何从ionic 4中的app.component获取当前页面? [英] how we can get the current page from app.component in ionic 4?

查看:466
本文介绍了我们如何从ionic 4中的app.component获取当前页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在ionic 4中的app.component中获取当前页面实例.

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

在离子3中,我可以这样做

in ionic 3 i can do it like this

this.nav.getActive().instance

推荐答案

您可以从路由器访问该网址.

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

这篇关于我们如何从ionic 4中的app.component获取当前页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆