Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get canGoBack functionality in Ionic 5?

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();
...

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?

like image 624
VahidNaderi Avatar asked May 14 '20 13:05

VahidNaderi


Video Answer


1 Answers

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

    // if (this.routerOutlet.canGoBack()) or whatevet...
like image 104
Mostafa Harb Avatar answered Oct 03 '22 04:10

Mostafa Harb