Ion 4 setroot with angle router

I am upgrading my Ionic 3 project to the latest Ionic 4, and I have some trouble with routing. In Ionic 3 I use setRoot like this:

< /p>

handler: () => navCtrl.parent.parent.setRoot(HomePage,'logout', (animate: true))

The latest of Ionic 4 navCtrl only has goBack, goForward and goRoot, I don’t understand how to use parent. I found ActivatedRoute in Angular, but I don’t think this is the right way. How can I do it?

Generally speaking, and quote this awesome article on this matter by Josh Morony:

< /p>

In Ionic 4 with Angular routing, there is no root page to be defined.

Because Ionic 4 depends on Angular Routers, so NavController has changed to reflect this new reality, and for Angular applications, there is no such thing as a “root” route. You only need to switch between paths and the framework will do the rest.

Generally speaking, navigateRoot, navigateBackward and navigateForward methods are only used to instruct Ionic how to handle animation. So you can use navigateRoot in Ionic 4 to accomplish the same function you used setRoot on Ionic 3.

I strongly recommend that you read the above article, it covers many things you need to know when migrating routing from Ionic version 3 to version 4.

I have upgraded my Ionic 3 project to the latest Ionic 4, and I have some trouble with routing. In Ionic 3 I use setRoot like this:

handler: () => navCtrl.parent.parent.setRoot(HomePage,'logout', (animate: true))

Ionic 4’s latest navCtrl only has goBack, goForward and goRoot, I don’t understand how to use parent. I found ActivatedRoute in Angular, but I don’t think this is the right way. How can I do it?

In general, and quote this awesome article on this matter by Josh Morony:

In Ionic 4 with Angular routing, there is no root page to be defined.

Because Ionic 4 relies on Angular routers, NavController has been changed to reflect this new Reality, and for Angular applications, there is no such thing as “root” routing. You only need to convert between paths and the framework will do the rest.

Generally speaking, navigateRoot, navigateBackward And navigateForward methods are only used to instruct Ionic how to handle animation. So you can use navigateRoot in Ionic 4 to accomplish the same function you use setRoot on Ionic 3.

I strongly recommend you to read the above article, it Covers many things you need to know when migrating routing from Ionic version 3 to version 4.

Leave a Comment

Your email address will not be published.