import * as React from "react"; import { Routes, Route, Outlet, Link } from "react-router-dom"; const About = React.lazy(() => import("./pages/About")); const Dashboard = React.lazy(() => import("./pages/Dashboard")); export default function App() { return (
This example demonstrates how to lazily load both route elements and even entire portions of your route hierarchy on demand. To get the full effect of this demo, be sure to open your Network tab and watch the new bundles load dynamically as you navigate around.
The "About" page is not loaded until you click on the link. When you do,
a <React.Suspense fallback> renders while the code is
loaded via a dynamic import() statement. Once the code
loads, the fallback is replaced by the actual code for that page.
The "Dashboard" page does the same thing, but takes it even one step
further by dynamically defining additional routes once the page
loads! Since React Router lets you declare your routes as
<Route> elements, you can easily define more routes
by placing an additional <Routes> element anywhere
further down the element tree. Just be sure the parent route ends with a{" "}
* like <Route path="dashboard/*"> in
this case.
Go to the home page