From 371a52efde83635c95387d1931f8ceceea6d6378 Mon Sep 17 00:00:00 2001 From: Jacob Ebey Date: Tue, 19 Oct 2021 09:22:03 -0700 Subject: [PATCH 1/2] feat: allow path on index routes --- .../__tests__/index-routes-test.tsx | 38 ++++++++++++++++++- packages/react-router/index.tsx | 1 + 2 files changed, 38 insertions(+), 1 deletion(-) 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..6d8e351044 100644 --- a/packages/react-router/index.tsx +++ b/packages/react-router/index.tsx @@ -213,6 +213,7 @@ export interface LayoutRouteProps { export interface IndexRouteProps { element?: React.ReactElement | null; index: true; + path?: string; } /** From 650313d1af80da385c8ab213f6f0c43b9ed9fb98 Mon Sep 17 00:00:00 2001 From: Jacob Ebey Date: Tue, 19 Oct 2021 14:21:49 -0700 Subject: [PATCH 2/2] added case sensitive to props --- packages/react-router/index.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/react-router/index.tsx b/packages/react-router/index.tsx index 6d8e351044..95642af58c 100644 --- a/packages/react-router/index.tsx +++ b/packages/react-router/index.tsx @@ -211,6 +211,7 @@ export interface LayoutRouteProps { } export interface IndexRouteProps { + caseSensitive?: boolean; element?: React.ReactElement | null; index: true; path?: string;