@@ -895,6 +895,70 @@ describe('React Router - Optional Path Parameters', () => {
895
895
expect ( JSON . parse ( paramsElement . textContent ! ) ) . toEqual ( expectedParams )
896
896
} ,
897
897
)
898
+
899
+ it . each ( [
900
+ {
901
+ path : '/chambres' ,
902
+ expected : {
903
+ rooms : 'chambres' ,
904
+ locale : 'undefined' ,
905
+ } ,
906
+ } ,
907
+ {
908
+ path : '/fr/chambres' ,
909
+ expected : {
910
+ rooms : 'chambres' ,
911
+ locale : 'fr' ,
912
+ } ,
913
+ } ,
914
+ {
915
+ path : '/rooms' ,
916
+ expected : {
917
+ rooms : 'rooms' ,
918
+ locale : 'undefined' ,
919
+ } ,
920
+ } ,
921
+ {
922
+ path : '/en/rooms' ,
923
+ expected : {
924
+ rooms : 'rooms' ,
925
+ locale : 'en' ,
926
+ } ,
927
+ } ,
928
+ ] ) (
929
+ 'should handle routes with required param after optional param: $path' ,
930
+ async ( { path, expected } ) => {
931
+ const rootRoute = createRootRoute ( )
932
+ const roomsRoute = createRoute ( {
933
+ getParentRoute : ( ) => rootRoute ,
934
+ path : '/{-$locale}/$rooms' ,
935
+ component : ( ) => {
936
+ const { locale, rooms } = roomsRoute . useParams ( )
937
+ return (
938
+ < div >
939
+ < h1 > Rooms</ h1 >
940
+ < div data-testid = "locale-param" > { locale ?? 'undefined' } </ div >
941
+ < div data-testid = "rooms-param" > { rooms ?? 'undefined' } </ div >
942
+ < Outlet />
943
+ </ div >
944
+ )
945
+ } ,
946
+ } )
947
+
948
+ window . history . replaceState ( { } , '' , path )
949
+
950
+ const router = createRouter ( {
951
+ routeTree : rootRoute . addChildren ( [ roomsRoute ] ) ,
952
+ } )
953
+
954
+ render ( < RouterProvider router = { router } /> )
955
+ await act ( ( ) => router . load ( ) )
956
+ const roomsParam = await screen . findByTestId ( 'rooms-param' )
957
+ expect ( roomsParam ) . toHaveTextContent ( expected . rooms )
958
+ const localeParam = await screen . findByTestId ( 'locale-param' )
959
+ expect ( localeParam ) . toHaveTextContent ( expected . locale )
960
+ } ,
961
+ )
898
962
} )
899
963
900
964
describe ( 'edge cases and error handling' , ( ) => {
0 commit comments