Lazy Route Discovery is a performance optimization that loads route information progressively as users navigate through your application, rather than loading the complete route manifest upfront.
With Lazy Route Discovery enabled (the default), React Router sends only the routes needed for the initial server-side render in the manifest. As users navigate to new parts of your application, additional route information is fetched dynamically and added to the client-side manifest.
The route manifest contains metadata about your routes (JavaScript/CSS imports, whether routes have loaders
/actions
, etc.) but not the actual route module implementations. This allows React Router to understand your application's structure without downloading unnecessary route information.
When a user navigates to a new route that isn't in the current manifest:
/__manifest
endpointTo prevent navigation waterfalls, React Router implements eager route discovery. All <Link>
and <NavLink>
components rendered on the current page are automatically discovered via a batched request to the server.
This discovery request typically completes before users click any links, making subsequent navigation feel synchronous even with lazy route discovery enabled.
// Links are automatically discovered by default
<Link to="/dashboard">Dashboard</Link>
// Opt out of discovery for specific links
<Link to="/admin" discover="none">Admin</Link>
Lazy Route Discovery provides several performance improvements:
You can configure route discovery behavior in your react-router.config.ts
:
export default {
// Default: lazy discovery with /__manifest endpoint
routeDiscovery: {
mode: "lazy",
manifestPath: "/__manifest",
},
// Custom manifest path (useful for multiple apps on same domain)
routeDiscovery: {
mode: "lazy",
manifestPath: "/my-app-manifest",
},
// Disable lazy discovery (include all routes initially)
routeDiscovery: { mode: "initial" },
} satisfies Config;
When using lazy route discovery, ensure your deployment setup handles manifest requests properly:
/__manifest
requests reach your React Router handlerversion
and p
query parameters in your cache key for the manifest endpointmanifestPath
if running multiple React Router applications on the same domain