Force ionic sidemenu to do pop instead setRoot


#1

Hi guys, i’ve a mobile app and this haven’t a home screen, then i would like to set the navigation to two pages using navCtrl.pop instead navCtrl.setRoot…

How can i achieve this?

Thanks in advance


#2

Hey @temohpab. Can you elaborate what you want to achieve? It’s difficult to understand your target


#3

I have a sidemenu and if i click into an element of the sidemenu and then the back button is pressed the app exits… But i need to come back to the previous page, not leave the app

It’s the sidemenu click doing a navCtrl.setRoot() ?


#4

Yep. @temohpab basically sidemenu’s on click function set your pressed page/button to root. You can achieve your desired results by changing it to

navCtrl.push(yourPage);


#5

Ok, this is a partial solution because now i can click in the sidemenu two times (or multiple times) in the same page and have a big stack of pages… How can i prevent to stack multiple pages? There are a limit or some logic to prevent this?


#6

@temohpab Have no idea about that because basically side menus are used to set starting points for a long process or easy access. I showed menu on just my index/main page and on the other pages just a back button. So user won’t be able to push multiple pages. If he has to navigate to another option then he has to get back to index page. This served me the purpose :slight_smile:


#7

Think on twitter for example… If you click in a sidemenu element you can go back to the previous page (and doesn’t exit from the app).

That’s the behaviour i want


#8

Try adding the below code it may help.

this.app.getRootNav().push(yourpage)

Add this to your import list.
import { App } from 'ionic-angular';

This in your constructor.
constructor(public app: App)