Skip to content
This repository was archived by the owner on Nov 15, 2024. It is now read-only.

Commit 29e02a3

Browse files
heygradytimdorr
authored andcommitted
fix regression to allow for empty-string paths (remix-run#6942)
1 parent a32f779 commit 29e02a3

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

packages/react-router/modules/__tests__/matchPath-test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,23 @@ describe("matchPath", () => {
99
});
1010
});
1111

12+
describe('with path=""', () => {
13+
it('returns correct url at "/"', () => {
14+
const path = "";
15+
const pathname = "/";
16+
const match = matchPath(pathname, path);
17+
// TODO: why is match.url "/" instead of ""?
18+
expect(match.url).toBe("/");
19+
});
20+
21+
it('returns correct url at "/somewhere/else"', () => {
22+
const path = "";
23+
const pathname = "/somewhere/else";
24+
const match = matchPath(pathname, path);
25+
expect(match.url).toBe("");
26+
});
27+
});
28+
1229
describe('with path="/"', () => {
1330
it('returns correct url at "/"', () => {
1431
const path = "/";

packages/react-router/modules/matchPath.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function matchPath(pathname, options = {}) {
3535
const paths = [].concat(path);
3636

3737
return paths.reduce((matched, path) => {
38-
if (!path) return null;
38+
if (!path && path !== "") return null;
3939
if (matched) return matched;
4040

4141
const { regexp, keys } = compilePath(path, {

0 commit comments

Comments
 (0)