Error on navCtrl.popToRoot() only sometimes with ion-tabs


#1

I recently upgraded ionic to the latest version (from 3.2.1 to 3.6.1) and encountered this error when calling navCtrl.popToRoot().

Runtime Error
Uncaught (in promise): removeView was not found

This happens when I load a page that has ion-tabs and try to pop() without changing a tab. If I select a different tab before calling pop(), the error doesn’t show. If I select a different tab, then select the first tab again, the error also doesn’t show.

Any ideas? Let me know if you need more info.


#2

Hi @appgod,

May be because you are loading the page, ionic forget the back histroy for sending you back on the page.

Instead you can follow below mentioned method.

import { NavController, App, LoadingController, ToastController } from 'ionic-angular';

import App in your component and add that in your constructor argument.

constructor(public app: App)

After that when ever you want to go back to root you can add below mentioned code in that function.

let nav = this.app.getRootNav();
nav.setRoot(LoginPage);

Hope this will work for you.


#3

Thanks that helped.

Originally I had it set to setRoot(‘LoginPage’) (notice the lazy loading) and in the previous post I was trying to use popToRoot() because setRoot() wasn’t working.

Well, I changed it to setRoot(LoginPage) and added LoginPage to the declarations in app.module.ts and now it works.

I didn’t have to inject App into the constructor.

Hopefully this helps someone and if anyone knows a better way of accomplishing this, please let me know.