-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Closed
Description
It is possible to have an empty-string path. Prior to the breaking change this would essentially match anything.
I changed the check to be more specific:
// improve the bail to allow empty-string paths
if (!path && path !== '') return null;// I added this test to `matchPath-test.js`
describe('with path=""', () => {
it('returns correct url at ""', () => {
const path = "";
const pathname = "/";
const match = matchPath(pathname, path);
expect(match.url).toBe("/"); // <-- weird 🤷🏻♂️
});
it('returns correct url at "/somewhere/else"', () => {
const path = "";
const pathname = "/somewhere/else";
const match = matchPath(pathname, path);
expect(match.url).toBe(""); // <-- expected
});
});I confirmed the above changes fixed the issue for my app.
I was relying on empty-string paths in my app to enable a custom route config where I needed a conceptual route that always matched. Upgrading to v5.0.1 broke my app and I couldn't figure out why.
Metadata
Metadata
Assignees
Labels
No labels