1

I'm working on an Angular application with lazy loading for the dashboard screen. I've encountered an issue where the submenu is not functioning properly when the dashboard is loaded lazily. Below is the relevant code and structure:

app-layout-component.html

<app-main-header></app-main-header>

<!-- Main Sidebar Container -->
<app-main-sidebar></app-main-sidebar>

<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
  <router-outlet></router-outlet>
</div>

<!-- Control Sidebar -->
<aside class="control-sidebar control-sidebar-dark">
  <!-- Control sidebar content goes here -->
</aside>

<!-- Main Footer -->
<app-main-footer></app-main-footer>

app-routing.module.ts

onst routes: Routes = [
  {
    path: AppRoutes.login,
    component: LoginComponent,
  },
  {
    path: AppRoutes.newReg,
    component: NewRegistrationComponent,
  },
  {
    path: AppRoutes.forgotPass,
    component: RegisterRecoverComponent,
  },
  {
    path: '',
    component: AuthenticationComponent,
    canActivate: [defaultScreenGuard] // Navigate to login if QuickRegEnabled is set to false 
  },
  { 
    path: 'dashboard', 
    loadChildren: () => import('./shared/components/app-layout/app-layout.module').then(m => m.AppLayoutModule)
  },
];

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

sub-menu code in main-header component

 <li class="nav-item">
          <a href="#" class="nav-link">
            <i class="nav-icon fas fa-copy"></i>
            <p>
              Layout Options
              <i class="fas fa-angle-left right"></i>
            </p>
          </a>
          <ul class="nav nav-treeview">
            <li class="nav-item">
              <a  class="nav-link">
                <i class="far fa-circle nav-icon"></i>
                <p>Top Navigation</p>
              </a>
            </li>
            <li class="nav-item">
              <a  class="nav-link">
                <i class="far fa-circle nav-icon"></i>
                <p>Top Navigation + Sidebar</p>
              </a>
            </li>
            <li class="nav-item">
              <a  class="nav-link">
                <i class="far fa-circle nav-icon"></i>
                <p>Boxed</p>
              </a>
            </li>
            <li class="nav-item">
              <a  class="nav-link">
                <i class="far fa-circle nav-icon"></i>
                <p>Fixed Sidebar</p>
              </a>
            </li>
            <li class="nav-item">
              <a  class="nav-link">
                <i class="far fa-circle nav-icon"></i>
                <p>Fixed Sidebar <small>+ Custom Area</small></p>
              </a>
            </li>
            <li class="nav-item">
              <a  class="nav-link">
                <i class="far fa-circle nav-icon"></i>
                <p>Fixed Navbar</p>
              </a>
            </li>
            <li class="nav-item">
              <a  class="nav-link">
                <i class="far fa-circle nav-icon"></i>
                <p>Fixed Footer</p>
              </a>
            </li>
            <li class="nav-item">
              <a  class="nav-link">
                <i class="far fa-circle nav-icon"></i>
                <p>Collapsed Sidebar</p>
              </a>
            </li>
          </ul>
        </li>

When I navigate to the dashboard after a successful login, the submenu within the dashboard is not working. It is not opening, but redirecting it to default page because url becomes localhost:4200/#. However, if I place the same code directly in app.component.html, it works fine. I am using adminlte template in this project.

Why is the submenu not working when the dashboard is loaded lazily? Is there something I might be missing in the lazy loading configuration or in the component structure?

6
  • What does 'not working' mean? Doesn't display? Throws error? Commented Aug 1, 2024 at 11:18
  • it is not opening, but redirecting it to default page because url becomes localhost:4200/# Commented Aug 1, 2024 at 11:32
  • You probably forgot to provide something. What library are you using for opening menu? Commented Aug 1, 2024 at 11:39
  • I am using AdminLte template not library Commented Aug 1, 2024 at 11:45
  • There may be conflicts when using "href" instead of [routerLink], what version of angular we talking about? Commented Aug 1, 2024 at 18:44

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.