@@ -159,12 +159,28 @@ export type ReactRouterConfig = {
159159 */
160160 presets ?: Array < Preset > ;
161161 /**
162- * Control the "Lazy Route Discovery" behavior. By default, this resolves to
163- * `lazy` which will lazily discover routes as the user navigates around your
164- * application. You can set this to `initial` to opt-out of this behavior and
165- * load all routes with the initial HTML document load.
162+ * Control the "Lazy Route Discovery" behavior.
163+ *
164+ * - `routeDiscovery.mode`: By default, this resolves to `lazy` which will
165+ * lazily discover routes as the user navigates around your application.
166+ * You can set this to `initial` to opt-out of this behavior and load all
167+ * routes with the initial HTML document load.
168+ * - `routeDiscovery.manifestPath`: The path to serve the manifest file from.
169+ * Only applies to `mode: "lazy"` and defaults to `/__manifest`.
170+ *
171+ * If you do not need to control the manifest, you can specify the mode
172+ * directly on the `routeDiscovery` config.
166173 */
167- routeDiscovery ?: "lazy" | "initial" ;
174+ routeDiscovery ?:
175+ | "lazy"
176+ | "initial"
177+ | {
178+ mode ?: "lazy" ; // Can only adjust the manifest path in `lazy` mode
179+ manifestPath : string ;
180+ }
181+ | {
182+ mode : "initial" ;
183+ } ;
168184 /**
169185 * The file name of the server build output. This file
170186 * should end in a `.js` extension and should be deployed to your server.
@@ -218,7 +234,10 @@ export type ResolvedReactRouterConfig = Readonly<{
218234 * application. You can set this to `initial` to opt-out of this behavior and
219235 * load all routes with the initial HTML document load.
220236 */
221- routeDiscovery : ReactRouterConfig [ "routeDiscovery" ] ;
237+ routeDiscovery : {
238+ mode : "lazy" | "initial" ;
239+ manifestPath : string ;
240+ } ;
222241 /**
223242 * An object of all available routes, keyed by route id.
224243 */
@@ -397,7 +416,6 @@ async function resolveConfig({
397416 let defaults = {
398417 basename : "/" ,
399418 buildDirectory : "build" ,
400- routeDiscovery : "lazy" ,
401419 serverBuildFile : "index.js" ,
402420 serverModuleFormat : "esm" ,
403421 ssr : true ,
@@ -414,7 +432,7 @@ async function resolveConfig({
414432 buildDirectory : userBuildDirectory ,
415433 buildEnd,
416434 prerender,
417- routeDiscovery,
435+ routeDiscovery : userRouteDiscovery ,
418436 serverBuildFile,
419437 serverBundles,
420438 serverModuleFormat,
@@ -441,17 +459,43 @@ async function resolveConfig({
441459 ) ;
442460 }
443461
444- if ( routeDiscovery === "lazy" && ! ssr ) {
445- if ( userAndPresetConfigs . routeDiscovery === "lazy" ) {
446- // If the user set "lazy" and `ssr:false`, then it's an invalid config
447- // and we want to fail the build
462+ let routeDiscovery : ResolvedReactRouterConfig [ "routeDiscovery" ] = {
463+ mode : "lazy" ,
464+ manifestPath : "/__manifest" ,
465+ } ;
466+
467+ if ( userRouteDiscovery == null ) {
468+ if ( ! ssr ) {
469+ // No FOW when SSR is disabled
470+ routeDiscovery . mode = "initial" ;
471+ } else {
472+ // no-op - use defaults
473+ }
474+ } else if (
475+ userRouteDiscovery === "initial" ||
476+ ( typeof userRouteDiscovery === "object" &&
477+ userRouteDiscovery . mode === "initial" )
478+ ) {
479+ routeDiscovery . mode = "initial" ;
480+ } else {
481+ if ( ! ssr ) {
448482 return err (
449- 'The `routeDiscovery` config cannot be set to "lazy" when setting `ssr:false`'
483+ 'The `routeDiscovery` config must be left unset or set to "initial" ' +
484+ "when setting `ssr:false`"
450485 ) ;
451- } else {
452- // But if the user didn't specify, then we want to default to "initial"
453- // when SSR is disabled
454- routeDiscovery = "initial" ;
486+ }
487+ if ( typeof userRouteDiscovery === "object" ) {
488+ if (
489+ userRouteDiscovery . manifestPath != null &&
490+ ! userRouteDiscovery . manifestPath . startsWith ( "/" )
491+ ) {
492+ return err (
493+ "The `routeDiscovery.manifestPath` config must be a root-relative " +
494+ 'pathname beginning with a slash (i.e., "/__manifest")'
495+ ) ;
496+ }
497+ routeDiscovery . manifestPath =
498+ userRouteDiscovery . manifestPath ?? "/__manifest" ;
455499 }
456500 }
457501
0 commit comments