如何设置默认登录页面并在登录后打开ionic-4中的选项卡

问题描述 投票:2回答:2

我正在创建离子选项卡项目,我想在打开选项卡后设置默认登录页面。我设置在默认登录页面但登录后我没有获得离子4的标签。请帮助我如何解决这个问题....?

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 {}

APP-routing.module.ts

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

const routes: Routes = [
  { path: '', redirectTo: 'login', pathMatch: 'full' },
  { path: 'tabs/tab1', loadChildren: './tabs/tabs.module#TabsPageModule' },
  { path: 'login', loadChildren: './login/login.module#LoginPageModule' },
  { path: 'register', loadChildren: './register/register.module#RegisterPageModule' }
];
@NgModule({
  imports: [
    RouterModule.forRoot(routes, { preloadingStrategy: PreloadAllModules })
  ],
  exports: [RouterModule]
})
export class AppRoutingModule {}

我正在更改路线,但没有获得标签请帮我如何在登录后添加路线以打开标签。

angular ionic4
2个回答
3
投票

这应该工作。

tabs.router.module.ts

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

APP-routing.module.ts

...
const routes: Routes = [
  { path: '', redirectTo: 'login', pathMatch: 'full' },
  { path: 'start', loadChildren: './tabs/tabs.module#TabsPageModule' },
  { path: 'login', loadChildren: './login/login.module#LoginPageModule' },
];
...

0
投票

APP-routing.module.ts

...

const routes: Routes = [
  { path: '', redirectTo: 'login', pathMatch: 'full' },
  { path: 'tabs', loadChildren: './tabs/tabs.module#TabsPageModule' },<--here
  { path: 'login', loadChildren: './login/login.module#LoginPageModule' },
];

tabs.router.module.ts

...

const routes: Routes = [
  {
    path: '',<--here
    component: TabsPage,
    children: [
      {
        path: 'tab1',
        children: [
          { path: '', loadChildren: '../tab1/tab1.module#Tab1PageModule'}
        ]
      },
      ...
      { path: 'tabs', redirectTo: '/tabs/tab1', pathMatch: 'full'}<--here
    ]
  }
];

...

导航:this.router.navigate(['tabs']);

© www.soinside.com 2019 - 2024. All rights reserved.