如何在 Ionic 5 中获得 canGoBack 功能? [英] How to get canGoBack functionality in Ionic 5?

查看:35
本文介绍了如何在 Ionic 5 中获得 canGoBack 功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在 Ionic 应用程序中放置一个后退按钮,并在它位于根目录中时隐藏后退按钮,根目录不是固定的,可以根据流程进行更改.我在这里找到了以下代码:

I'm trying to put a back button in Ionic app and to hide the back button when it's in the root, which the root is not fixed and can be changed based on the flow. I found the following code here:

...
constructor(
    private router: Router,
    private ionRouterOutlet: IonRouterOutlet
) {

}

ngOnInit() {
    this.canGoBack    = this.ionRouterOutlet.canGoBack();
...

如果它可以工作就好了,但 IonRouterOutlet 是组件,不能像这样注入到另一个组件中.关于如何在 Ionic 5 中使用 angular 完成它的任何想法?

It would be nice if it works but IonRouterOutlet is component and cannot be injected to another component like this. Any idea about how can it be done in Ionic 5 with angular?

推荐答案

@ViewChild(IonRouterOutlet, { static : true }) routerOutlet: IonRouterOutlet;

    // if (this.routerOutlet.canGoBack()) or whatevet...

这篇关于如何在 Ionic 5 中获得 canGoBack 功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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