@@ -83,6 +83,8 @@ type ServerBundlesBuildManifest = BaseBuildManifest & {
83
83
84
84
type ServerModuleFormat = "esm" | "cjs" ;
85
85
86
+ type ValidateConfigFunction = ( config : ReactRouterConfig ) => string | void ;
87
+
86
88
interface FutureConfig {
87
89
/**
88
90
* Enable route middleware
@@ -356,11 +358,13 @@ async function resolveConfig({
356
358
viteNodeContext,
357
359
reactRouterConfigFile,
358
360
skipRoutes,
361
+ validateConfig,
359
362
} : {
360
363
root : string ;
361
364
viteNodeContext : ViteNode . Context ;
362
365
reactRouterConfigFile ?: string ;
363
366
skipRoutes ?: boolean ;
367
+ validateConfig ?: ValidateConfigFunction ;
364
368
} ) : Promise < Result < ResolvedReactRouterConfig > > {
365
369
let reactRouterUserConfig : ReactRouterConfig = { } ;
366
370
@@ -383,6 +387,13 @@ async function resolveConfig({
383
387
}
384
388
385
389
reactRouterUserConfig = configModule . default ;
390
+
391
+ if ( validateConfig ) {
392
+ const error = validateConfig ( reactRouterUserConfig ) ;
393
+ if ( error ) {
394
+ return err ( error ) ;
395
+ }
396
+ }
386
397
} catch ( error ) {
387
398
return err ( `Error loading ${ reactRouterConfigFile } : ${ error } ` ) ;
388
399
}
@@ -631,11 +642,13 @@ export async function createConfigLoader({
631
642
watch,
632
643
mode,
633
644
skipRoutes,
645
+ validateConfig,
634
646
} : {
635
647
watch : boolean ;
636
648
rootDirectory ?: string ;
637
649
mode : string ;
638
650
skipRoutes ?: boolean ;
651
+ validateConfig ?: ValidateConfigFunction ;
639
652
} ) : Promise < ConfigLoader > {
640
653
root = Path . normalize ( root ?? process . env . REACT_ROUTER_ROOT ?? process . cwd ( ) ) ;
641
654
@@ -660,7 +673,13 @@ export async function createConfigLoader({
660
673
updateReactRouterConfigFile ( ) ;
661
674
662
675
let getConfig = ( ) =>
663
- resolveConfig ( { root, viteNodeContext, reactRouterConfigFile, skipRoutes } ) ;
676
+ resolveConfig ( {
677
+ root,
678
+ viteNodeContext,
679
+ reactRouterConfigFile,
680
+ skipRoutes,
681
+ validateConfig,
682
+ } ) ;
664
683
665
684
let appDirectory : string ;
666
685
0 commit comments