I want apply lazy loading to specific routes. I want something like this:
import { lazy, Suspense } from "react";
import { Route, Routes } from "react-router-dom";
import NotLazyComponent from "./NotLazyComponent";
const LazyOne = lazy(() => import("./LazyOne"));
const LazyTwo = lazy(() => import("./LazyTwo"));
const App = () => {
return (
<Routes>
<Route path="/not-lazy" element={<NotLazyComponent />} />
<Suspense fallback={<div>Loading...</div>}>
<Route path="/lazy-one" element={<LazyOne />} />
<Route path="/lazy-two" element={<LazyTwo />} />
</Suspense>
</Routes>
);
};
export default App;
but this won't work. What is the correct way to do that?