'Is that possible to import group of pages in react lazy

I want to separate my app into 2 parts.

  • When I open Page1 - I want bundle to import only it.
  • When I open one of Page2, Page3 or Page4 - I want bundle to import all these pages at once.

Is that possible to implement it with react lazy? Something like this:

const Page1 = lazy(() => import("./pages/Page1"));
const { Page2, Page3, Page4 } = lazy(() => {
    import("./pages/Page2")
    import("./pages/Page3")
    import("./pages/Page4")
});


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source