简体   繁体   English

在Ionic 2应用程序中导航NavController已解决! 但在Ionic 3中却没有

[英]Navigation NavController in Ionic 2 app SOLVED! but not in Ionic 3

I'm building an app with Ionic 2 and my question relates the navigation, it is not easy to explain but I'll try: 我正在使用Ionic 2构建应用程序,但我的问题与导航有关,不容易解释,但我将尝试:

I have a page (MyFilePage), with a list of files from a cloud, in which I recall the navCtrl.push() on it, for recursive navigation in folders. 我有一个页面(MyFilePage),其中包含来自云的文件列表,我在其中回忆起navCtrl.push(),用于在文件夹中进行递归导航。 On this page I have an ion-fab button who sends me, with push(), to another page (UplaodPage), with the list of file in the memory's device. 在此页面上,我有一个ion-fab按钮,该按钮通过push()将我发送到另一页(UplaodPage),其中包含内存设备中的文件列表。 In this page I recall the method push() on it, as the other page, for recursive navigation in folders. 在此页面中,我记得它的方法push()和另一页一样,用于在文件夹中进行递归导航。 After that I select the file I want to upload, and what I would to do, is return to the last MyFilePage visited, (the one where I make the uplaod). 之后,我选择了要上传的文件,然后执行的操作将返回到上次访问的MyFilePage(我在其中进行升级)。

I post an image, ionic 2 app strucure , that may clarify the situation. 我发布了图像ionic 2应用程序结构 ,这可以弄清楚情况。

Thanks 谢谢

EDIT: This works nice on Ionic 2 with the method push(page: any, params?: any, opts?: NavOptions, done?: Function);, but not in Ionic 3, that have the method push(page: Page | string, params?: any, opts?: NavOptions, done?: Function): Promise;, where page is type of Page|string and the method getByIndex() returns a ViewController. 编辑:这在Ionic 2上使用push(page:any,params ?: any,opts ?: NavOptions,done ?: Function)方法很好;但在Ionic 3中,没有方法push(page:Page | string,params ?: any,opts ?: NavOptions,done ?: Function):Promise ;,其中page是Page | string的类型,方法getByIndex()返回一个ViewController。

Anyone have a solution? 有人有解决办法吗? Thanks 谢谢

If you want to keep pages: 如果要保留页面:

1- first you need to get the index of the page you want to back to and save in a provider(recommended) or storage. 1-首先,您需要获取要返回的页面的索引并保存在提供程序(推荐)或存储中。

let index = this.navCtrl.indexOf(this.navCtrl.getActive());

2- then you can go to the saved page like this: 2-然后您可以转到保存的页面,如下所示:

let selectedPage = this.navCtrl.getByIndex(index);
this.navCtrl.push(selectedPage );

and if you like to remove those pages: 并且如果您要删除这些页面:

1- first you need to get the index of the page you want to back to and also a counter when ever you push a page. 1-首先,您需要获取要返回到的页面的索引,并在每次推入页面时获得一个计数器。 then save them in a provider(recommended) or storage. 然后将它们保存在提供程序(推荐)或存储中。

2- then you can go to the selected page and remove the other like this: 2-然后您可以转到所选页面并删除另一个页面,如下所示:

this.navCtrl.remove(startIndex+1, removeCount);

for more info check NavController . 有关更多信息,请检查NavController

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM