How to set default login page and after login open tabs in ionic-4

后端 未结 3 1982
花落未央
花落未央 2021-01-06 06:05

I am creating ionic tabs project and I want to set in default login page then after open tabs . I am set in default login page but after login i am not getting tabs in ion

相关标签:
3条回答
  • 2021-01-06 06:42

    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
        ]
      }
    ];
    

    ...

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

    0 讨论(0)
  • 2021-01-06 07:05

    This should work.

    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 讨论(0)
  • 2021-01-06 07:05

    The Answer given by B.Mind is working fine for me. But with few changes.

    For Angular 8 and 9, the lazy load declaration changed. Since Angular 8 introduced the new recommended module loading method, previously the default method of lazy loading modules was to specify a string path to a module:

    { path: 'tab1', loadChildren: 'src/app/tabs/tab1.module#Tab2PageModule' }
    

    So Change it to

    { path: 'tab1', loadChildren: () => import('src/app/tabs/tab1.module').then(m => m.Tab2PageModule) }
    

    and navigate like this

    this.route.navigateByUrl('/tabs/tab1');
    
    0 讨论(0)
提交回复
热议问题