0

I have a module who has a big set of components that are accessed by different subroutes. I'm already lazy loading the module, but I'd like to know if it's possible to lazy load the subcomponents:

const appRoutes: Routes = [
  {
    path: '',
    component: HomeComponent,
    canActivate: [AuthGuardService],
    children: [
      {
        path: '',
        component: DashboardComponent,
        canActivate: [AuthGuardService]
      },
      {
        path: 'users',
        component: UsersComponent, // I want to lazy load that
        canActivate: [AuthGuardService]
      },
      {
        path: 'account',
        component: AccountComponent, // I want to lazy load that
        canActivate: [AuthGuardService]
      },
      {
        path: 'invoices',
        component: InvoicesComponent, // I want to lazy load that
        canActivate: [AuthGuardService]
      },
      {
        path: 'upgrade',
        component: StripeFormComponent, // I want to lazy load that
        canActivate: [AuthGuardService]
      }
    ]
  }
];

Any idea if that's possible?

1
  • This is probably a bad idea. Better to just use seperate modules in this case. Commented Mar 21, 2020 at 15:42

1 Answer 1

1

You can read about component lazy-loading there: https://johnpapa.net/angular-9-lazy-loading-components/ But i think that separate each component to module is better idea

Sign up to request clarification or add additional context in comments.

Comments

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.