diff --git a/packages/react-router/__tests__/index-routes-test.tsx b/packages/react-router/__tests__/index-routes-test.tsx index 3f5b57b61c..3022445252 100644 --- a/packages/react-router/__tests__/index-routes-test.tsx +++ b/packages/react-router/__tests__/index-routes-test.tsx @@ -1,4 +1,6 @@ -import { matchRoutes } from "react-router"; +import * as React from "react"; +import { create as createTestRenderer } from "react-test-renderer"; +import { matchRoutes, MemoryRouter, Routes, Route, Outlet } from "react-router"; describe("index route matching", () => { it("throws when the index route has children", () => { @@ -21,4 +23,38 @@ describe("index route matching", () => { ); }).toThrow("must not have child routes"); }); + + it("matches path on index route", () => { + let renderer = createTestRenderer( + + + Users} /> + + + ); + + expect(renderer.toJSON()).toMatchInlineSnapshot(` +

+ Users +

+ `); + }); + + it("throws when the index route with path has children", () => { + expect(() => { + matchRoutes( + [ + { + path: "/users", + index: true, + children: [ + // This config is not valid because index routes cannot have children + { path: ":id" } + ] + } + ], + "/users/mj" + ); + }).toThrow("must not have child routes"); + }); }); diff --git a/packages/react-router/index.tsx b/packages/react-router/index.tsx index 4c38b2317f..95642af58c 100644 --- a/packages/react-router/index.tsx +++ b/packages/react-router/index.tsx @@ -211,8 +211,10 @@ export interface LayoutRouteProps { } export interface IndexRouteProps { + caseSensitive?: boolean; element?: React.ReactElement | null; index: true; + path?: string; } /**