Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Path with optional parameter is not matched properly when a child with another parameter exists #10738

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions packages/react-router/__tests__/matchRoutes-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,31 @@ describe("matchRoutes", () => {
{ path: "*", element: <h1>Not Found</h1> },
];

let routesWithOptionalParameters: RouteObject[] = [
{
path: "/*",
element: <h1>Home</h1>,
children: [
{
path: "layout/:type?/*",
element: <p>Layout</p>,
children: [
{
path: ":details/*",
element: <p>details</p>,
children: [
{
path: "content",
element: <p>Content</p>,
},
],
},
],
},
],
},
];

it("matches root * routes correctly", () => {
expect(pickPaths(routes, "/not-found")).toEqual(["*"]);
expect(pickPaths(routes, "/hometypo")).toEqual(["*"]);
Expand Down Expand Up @@ -118,6 +143,13 @@ describe("matchRoutes", () => {
expect(matches[1].route).toBe(userProfileRoute);
});

it("matches parent path with optional parameter without matching any child", () => {
expect(pickPaths(routesWithOptionalParameters, "/layout/type1")).toEqual([
"/*",
"layout/:type?/*",
]);
});

describe("with a basename", () => {
it("matches a pathname that starts with the basename", () => {
expect(pickPaths(routes, "/app/users/mj", "/app")).toEqual([
Expand Down
Loading