带有 Angular Router 的 Ionic 4 setRoot [英] Ionic 4 setRoot with Angular Router
问题描述
我正在将我的 Ionic 3 项目升级到最新的 Ionic 4,但我在路由方面遇到了一些问题.在 Ionic 3 中,我使用 setRoot 就像这样:
I'm upgrading my Ionic 3 project to the latest Ionic 4 and I have some trouble with Routing. In Ionic 3 I used setRoot just like this:
handler: () => navCtrl.parent.parent.setRoot(HomePage, 'logout', {animate: true})
Ionic 4最新的navCtrl只有goBack、goForward和goRoot,不知道怎么用parent.我在 Angular 中找到了 ActivatedRoute,但我认为这不是正确的方法.我该怎么办?
The latest navCtrl of Ionic 4 has only goBack, goForward and goRoot, and 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?
推荐答案
一般来说,并引用 Josh Morony 关于这个问题的这篇很棒的文章:
在带有 Angular 路由的 Ionic 4 中,没有要定义的根页面.
In Ionic 4 with Angular routing, there is no root page to be defined.
因为 Ionic 4 依赖于 Angular 的路由器,所以 NavController 已被更改以反映这一新现实,并且对于 Angular 应用程序,没有像根"路由这样的东西.您只需在路由之间进行转换,框架就会完成其余的工作.
Because Ionic 4 relies on Angular's router, the NavController has been changed to reflect this new reality, and for an Angular application there is no such a thing like "root" route. You simply transition between routes and the framework does the rest of the work.
一般来说,navigateRoot
、navigateBackward
和navigateForward
方法在这里只是为了指导Ionic 如何处理动画.所以你可以在 Ionic 4 中使用 navigateRoot
来完成你在 Ionic 3 上使用 setRoot
的相同功能.
Generally speaking, the methods navigateRoot
, navigateBackward
and navigateForward
are here only to instruct Ionic on how to deal with animations. So you can use navigateRoot
in Ionic 4 to accomplish the same of what you used setRoot
on Ionic 3.
我强烈建议您阅读上述文章,它涵盖了将路由从 Ionic 版本 3 迁移到版本 4 时需要了解的很多内容.
I strongly recommend that you read the aforementioned article, it covers a lot of what you need to know to migrate your routes from version 3 to version 4 of Ionic.
这篇关于带有 Angular Router 的 Ionic 4 setRoot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!