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

Regression: empty string paths no longer match #6941

Closed
heygrady opened this issue Sep 26, 2019 · 2 comments · Fixed by #6942
Closed

Regression: empty string paths no longer match #6941

heygrady opened this issue Sep 26, 2019 · 2 comments · Fixed by #6942

Comments

@heygrady
Copy link
Contributor

heygrady commented Sep 26, 2019

https://github.com/ReactTraining/react-router/blob/0c058adc5b56c6d9b409af5e4d8330c645fac00c/packages/react-router/modules/matchPath.js#L38

Broken by 7bd1407 (#6715)

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.

@timdorr
Copy link
Member

timdorr commented Sep 27, 2019

Could you submit a PR to fix this?

@mjackson
Copy link
Member

This was released in 5.1.1 https://github.com/ReactTraining/react-router/releases/tag/v5.1.1

@lock lock bot locked as resolved and limited conversation to collaborators Nov 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants