Ionic split page side menu not loading up with url redirects and lazy loading

Hi,
I have been using IONIC Split pane with Angular 12.2.5, NGRX, Ionic-router-outlet. But for some reason when I am lazy loading the child components the side menu on the home page doesn’t load until i hit refresh. It work fine if i preload the child component without lazy loading. Which is not ideal Below is my code.

app.module.ts

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouteReuseStrategy } from '@angular/router';
import { EffectsModule } from '@ngrx/effects';
import { StoreDevtoolsModule } from '@ngrx/store-devtools';
import { ReactiveComponentModule } from '@ngrx/component';

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

import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { StoreModule } from '@ngrx/store';

import * as fromApp from './store/app.reducer';
import { AuthEffects } from './auth/store/auth-store.effects';
import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
import { environment } from 'src/environments/environment';
import { SharedCutomModule } from './shared/shared.module';
import { HomePageModule } from './home/home.module';
import { AuthInterceptorService } from './auth/auth-interceptor/auth-interceptor.service';

@NgModule({
  declarations: [AppComponent],
  entryComponents: [],
  imports: [
    BrowserModule,
    IonicModule.forRoot(),
    AppRoutingModule,
    BrowserAnimationsModule,
    HttpClientModule,
    SharedCutomModule,
    HomePageModule,
    // StoreModule.forRoot(fromApp.appReducer, {}),
    StoreModule.forRoot(fromApp.appReducer),
    StoreDevtoolsModule.instrument({
      maxAge: 25, // Retains last 25 states
      logOnly: environment.production, // Restrict extension to log-only mode
    }),
    EffectsModule.forRoot([AuthEffects]),
    ReactiveComponentModule,
  ],
  providers: [
    {
      provide: HTTP_INTERCEPTORS,
      useClass: AuthInterceptorService,
      multi: true,
    },
    { provide: RouteReuseStrategy, useClass: IonicRouteStrategy },
  ],
  bootstrap: [AppComponent],
})
export class AppModule {}

app-routing.module.ts

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

const routes: Routes = [
  {
    path: '',
    pathMatch: 'full',
    redirectTo: 'folder/inbox',
  },
  {
    path: 'auth-login',
    loadChildren: () =>
      import('./auth/auth-login/auth-login.module').then(
        (m) => m.AuthLoginPageModule
      ),
  },
  {
    path: 'auth-signup',
    loadChildren: () =>
      import('./auth/auth-signup/auth-signup.module').then(
        (m) => m.AuthSignupPageModule
      ),
  },
];

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

app.component.html

<ion-app>
  <app-home></app-home>
</ion-app>

home.module.ts

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';

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

import { HomePageRoutingModule } from './home-routing.module';

import { HomePage } from './home.page';
import { SharedCutomModule } from '../shared/shared.module';
import { FolderPageModule } from '../folder/folder.module';

@NgModule({
  imports: [
    CommonModule,
    FormsModule,
    IonicModule,
    HomePageRoutingModule,
    SharedCutomModule
  ],
  declarations: [HomePage],
  exports: [HomePage],
})
export class HomePageModule {}

home-routing.module.ts

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { Role } from '../auth/enums/role.enum';
import { AuthGuard } from '../auth/guards/auth.guard';

import { HomePage } from './home.page';

const routes: Routes = [
  {
    path: '',
    component: HomePage,
    canActivate: [AuthGuard],
    data: { roles: [Role.athlete, Role.admin, Role.coach] },
    children: [
      {
        path: 'folder/:id',
        loadChildren: () =>
          import('../folder/folder.module').then((m) => m.FolderPageModule),
      },
      {
        path: '',
        redirectTo: 'folder/Inbox',
        pathMatch: 'full',
      },
    ],
  },
  {
    path: '',
    redirectTo: 'folder/Inbox',
    pathMatch: 'full',
  },
];

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

It happens when I go to login page after clicking on logout and then login which will take me to ’ ’ route and in turn it redirects me to folder/inbox which is the child module of home page module lazy loaded. When it does it doesn’t load the menu on the home page module.

1 Like