简体   繁体   English

如何使用Ionic 2框架创建登录页面,然后导致选项卡式视图?

[英]How can I create a login page using Ionic 2 framework that then leads to a tabbed view?

Currenty, in my app.html file, I have: Currenty,在我的app.html文件中,我有:

<ion-tabs>
    <ion-tab [root]="tab1Root" tabTitle="Tab1" tabIcon="time"></ion-tab>
    <ion-tab [root]="tab2Root" tabTitle="Tab2" tabIcon="paper"></ion-tab>
    <ion-tab [root]="tab3Root" tabTitle="Tab3" tabIcon="more"></ion-tab>
</ion-tabs>

and in my app.js file, after doing the proper imports of these pages, I have: 在我的app.js文件中,在正确导入这些页面后,我有:

    this.tab1Root = Page1;
    this.tab2Root = Page2;
    this.tab3Root = Page3;

I want the application to open with a login page, and then from there progress to this tabbed view. 我希望应用程序打开一个登录页面,然后从那里进展到这个选项卡视图。 I'm not sure how to logically set this up in the context of app.html and app.js 我不确定如何在app.htmlapp.js的上下文中进行逻辑设置

I'm only interested in answers involving Ionic 2 (and Angular 2+), not the older versions. 我只对涉及Ionic 2(和Angular 2+)的答案感兴趣,而不是旧版本。

In your app, define this: 在您的应用中,定义以下内容:

export class YourApp {
  rootPage: Type = LoginPage;

  constructor(app: IonicApp, platform: Platform) {
    platform.ready().then(() => {

    });
  }
}

In your LoginPage, it should have this: 在您的LoginPage中,它应该具有:

export class LoginPage {
    constructor(nav: NavController) {
        this.nav = nav;
    }

    doLogin() {
        if (loginSuccessful) {
           this.nav.setRoot(YourTabsPage);
        }
    }
}

if your app is always opening with login page, you should: 如果您的应用始终以登录页面打开,您应该:

1- Put your login page in app.html 1-将您的登录页面放在app.html中

2- Import and inject NavController in your app.js constructor. 2-在app.js构造函数中导入并注入NavController

import {NavController} from 'ionic-framework/ionic';

constructor(nav: NavController) {
    this.nav = nav;
}

3- Create a new Tabs parent component. 3-创建新的Tabs父组件。 ( your current app.js ) and call it TabsParentComponent for example. (您当前的app.js)并将其称为TabsParentComponent。

4- In app.js, once the login is successful, call: 4-在app.js中,一旦登录成功,请致电:

this.nav.setRoot(TabsParentComponent)

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

相关问题 如何使用 ionic2 框架创建或自定义 Toast 视图 - How to create or customize a Toast view using ionic2 framework 如何在服务中创建一个返回 onSnapshot 结果的方法,然后在我的组件或 Ionic 页面中使用它? - How can I create a method in a service that returns the result of onSnapshot and then using it in my Component or Ionic Page? 无法使用选项卡式页面上的提供程序在 Angular 和 Ionic 中查询数据库 - Not able to query DB in Angular and Ionic using a provider on a Tabbed page 如何在 ionic 3 中创建折叠工具栏 - How can I create collapsing toolbar in ionic 3 如何使用角度和离子框架在手机中打开浏览器的一半屏幕 - How I can open a browser half of the screen in my mobile using angular and ionic framework 使用离子框架如何在选择器上方添加输入字段 - Using the ionic framework how can I add an input field above a picker 如何在离子2框架中使用ng-upgrade - How can I use ng-upgrade in ionic 2 framework 如何在ionic 2中创建叠加页面? - How to create an overlay page in ionic 2? 如何使用 Ionic Cli 在子文件夹中添加新页面 - How can I add new page in a sub folder using Ionic Cli 如何在 Ionic 5 中获取和查看 PDF (DocumentViewer)? - How can I get and view PDF (DocumentViewer) in Ionic 5?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM