Trung BìnhAngular iconAngular

Lazy loading route trong Angular hiện đại làm thế nào?

Với standalone component, route có thể dùng loadComponent; với feature có nhiều child routes, dùng loadChildren để import route array.

Ví dụ:

typescript
export const routes: Routes = [
  {
    path: "admin",
    loadComponent: () => import("./admin/admin.page").then(m => m.AdminPage),
  },
  {
    path: "settings",
    loadChildren: () => import("./settings/routes").then(m => m.SETTINGS_ROUTES),
  },
]

Nên đặt boundary theo feature/screen thật sự, không tách quá nhỏ khiến waterfall request tăng.

Xem toàn bộ Angular cùng filter theo level & chủ đề con.

Mở danh sách Angular