加载ionic 4应用程序时,模式页面会短暂出现

时间:2019-04-18 23:50:52

标签: angular typescript firebase ionic-framework ionic4

我有一个模式页面,该页面会在应用加载后瞬间消失。我想知道如何防止这种情况。

我正在使用一个标签页,底部有3个标签页。

  initializeApp() {
    firebase.initializeApp(firebaseConfig);

    this.platform.ready().then(() => {
        const unsubscribe = firebase.auth().onAuthStateChanged( user => {
          if (!user) {
            this.router.navigateByUrl('login');
            unsubscribe();
            console.log('if !user', user);
          } else {
            this.router.navigateByUrl('tabs');
            unsubscribe();
            console.log('if user', user);
          }
        });
      this.statusBar.styleDefault();
      this.splashScreen.hide();
    });
  }

标签页路线:

const routes: Routes = [
    {
        path: '',
        component: TabsPage,
        children: [
            { path: 'profile', loadChildren: '../../pages/profile/profile.module#ProfilePageModule'},
            { path: 'itinerary-feed', loadChildren: '../../pages/itinerary-feed/itinerary-feed.module#ItineraryFeedPageModule' },
            { path: 'messages', loadChildren: '../../pages/messages/messages.module#MessagesPageModule' },
        ]
    }
];

行程表页面是打开弹出模式的按钮所在的位置。该页面也是打开应用程序时的主页。

import { Component, OnInit } from '@angular/core';
import { ModalController } from '@ionic/angular';
import { CreateItineraryPage } from '../modals/create-itinerary/create-itinerary.page';

@Component({
  selector: 'app-itinerary-feed',
  templateUrl: './itinerary-feed.page.html',
  styleUrls: ['./itinerary-feed.page.scss'],
})
export class ItineraryFeedPage implements OnInit {

  constructor(private modalController: ModalController) { }

  ngOnInit() {
  }

  async presentModal(): Promise<void> {
      const modal = await this.modalController.create({
        component: CreateItineraryPage,
      });
      return await modal.present();
    }
}

最后,我将模式添加到我的app.module.ts

import { CreateItineraryPageModule } from './pages/modals/create-itinerary/create-itinerary.module';

@NgModule({
  declarations: [AppComponent],
  entryComponents: [],
  imports: [
    BrowserModule,
    IonicModule.forRoot(),
    AppRoutingModule,
    FormsModule,
    AngularFireAuthModule,
    CreateItineraryPageModule,
    AngularFireModule.initializeApp(firebaseConfig),
    ReactiveFormsModule],

因此,当我最初打开应用程序时,它会自动打开模式页面,一秒钟后它就会消失。但是真正的问题是,当我按下电话上的“后退”按钮时,它又回到了模式。我该如何预防?模态页面只是常规组件,没有任何内容。

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { Routes, RouterModule } from '@angular/router';

import { IonicModule } from '@ionic/angular';

import { CreateItineraryPage } from './create-itinerary.page';

const routes: Routes = [
  {
    path: '',
    component: CreateItineraryPage
  }
];

@NgModule({
  imports: [
    CommonModule,
    FormsModule,
    IonicModule,
    RouterModule.forChild(routes)
  ],
  declarations: [CreateItineraryPage]
})
export class CreateItineraryPageModule {}

最后,我从app-routing.module中删除了路由

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { AuthGuard } from './services/user/auth.guard';

const routes: Routes = [
  { path: 'login', loadChildren: './pages/login/login.module#LoginPageModule' },
  // TODO: SWITCH BACK AFTER DEVELOPMENT
  { path: 'settings', loadChildren: './pages/settings/settings.module#SettingsPageModule' },
  { path: 'reset-password', loadChildren: './pages/reset-password/reset-password.module#ResetPasswordPageModule' },
  { path: 'signup', loadChildren: './pages/signup/signup.module#SignupPageModule' },
  { path: 'tabs', loadChildren: './pages/tabs/tabs.module#TabsPageModule', canActivate: [AuthGuard]  },
  //{ path: 'create-itinerary', loadChildren: './pages/modals/create-itinerary/create-itinerary.module#CreateItineraryPageModule' },
];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule { }

The cross button opens the modal

0 个答案:

没有答案