ion-nav push在Ionic 4中无法正常工作

时间:2019-07-02 04:46:03

标签: angular ionic-framework ionic4

我试图将登录页面登录按钮添加到nav-push,但无法正常工作,任何人都知道如何在 Ionic-4

登录页面

  <ion-button icon-left size="medium" expand="full" shape="round" color="secondary" (click)="goToHome()" tappable>

        Sign in
      </ion-button>

.ts

import { NavController, MenuController, ToastController, AlertController, LoadingController } from '@ionic/angular';

constructor(
      public navCtrl: NavController,
      public menuCtrl: MenuController,

      public alertCtrl: AlertController,
      public loadingCtrl: LoadingController,

  ) { }
goToHome() {
    this.navCtrl.navigateRoot('/tab1');
  }

app-routing.module.ts

import { NgModule } from '@angular/core';
import { PreloadAllModules, RouterModule, Routes } from '@angular/router';

const routes: Routes = [
  { path: '', loadChildren: './pages/login/login.module#LoginPageModule' },
  { path: 'tabs', loadChildren: './tabs/tabs.module#TabsPageModule' },
  { path: 'tabs/tab1', loadChildren: './tab1/tab1.module#TabsPageModule' },
  { path: 'register', loadChildren: './pages/register/register.module#RegisterPageModule' },




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

tabs.router.module.ts

import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { TabsPage } from './tabs.page';

const routes: Routes = [
  {
    path: 'tabs',
    component: TabsPage,
    children: [
      {
        path: 'tab1',
        children: [
          {
            path: '',
            loadChildren: '../tab1/tab1.module#Tab1PageModule'
          }
        ]
      },
      {
        path: 'tab2',
        children: [
          {
            path: '',
            loadChildren: '../tab2/tab2.module#Tab2PageModule'
          }
        ]
      },
      {
        path: 'tab3',
        children: [
          {
            path: '',
            loadChildren: '../tab3/tab3.module#Tab3PageModule'
          }
        ]
      },
      {
        path: '',
        redirectTo: '/tabs/tab1',
        pathMatch: 'full'
      }
    ]
  },
  {
    path: '',
    redirectTo: '/tabs/tab1',
    pathMatch: 'full'
  }
];

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

1 个答案:

答案 0 :(得分:0)

Ionic 4路由已更改   this.navCtrl.navigateRoot('/ tab1');不再使用

现在,要完成最后一步并在我们的app-routing.module.ts文件中实现这些路由,它们将如下所示:

    const routes: Routes = [
{ path: '', redirectTo: '/home', pathMatch: 'full' },
{ path: 'home', loadChildren: '.../tab1/tab1.module#Tab1PageModule' },
{ path: 'products', loadChildren: './pages/products/products.module#ProductsModule'},
{ path: 'products/:id', loadChildren: '.../tab1/tab1.module#Tab1PageModule' },
{ path: 'products/categories', loadChildren: './pages/product-categories/product-categories.
{ path: 'support', loadChildren: '../tab1/tab1.module#Tab1PageModule' }
];
  

html页面中的setRoot

<ion-button href="/support" routerDirection="root">

或在课堂上

this.navCtrl.navigateRoot('/support');

<ion-button href="/products/12" routerDirection="forward">

this.navCtrl.navigateForward('/products/12');

Pop

<ion-button href="/products" routerDirection="backward">

<ion-back-button defaultHref="/products"></ion-back-button>

您还可以以编程方式向后导航:

this.navCtrl.navigateBack('/products');