Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

[WIP] Use Express-style path matching #12

Closed
wants to merge 1 commit into from
Closed

Conversation

taion
Copy link
Owner

@taion taion commented Apr 12, 2016

This is a remake of remix-run/react-router#3105.

This is not quite ready for release, as I want to make this an opt-in feature guarded behind a deprecation for now, as well as to update the documentation and examples as appropriate.

This PR changes the pattern matching algorithm from the home-grown React Router to path-to-regexp, which is used by Express and a number of other JavaScript routing frameworks.

The biggest advantages of this change are:

This will come with a few breaking changes once the feature is enabled:

  • Optional segments must be specified as /:foo? as with Express, rather than (/:foo) as with RR v1+ (but this is the syntax in v0.13.x)
  • Splats now come through as numbered parameters, rather than under splat
  • Repeated named parameters will take the last value, rather than collapsing into an array
  • Non-greedy splats are no longer supported; * is a greedy splat

In other words, Express's path matching works slightly differently to React Router's.

I expect that for the majority of applications, this should be fully drop-in. For the rest, the migration work will be relatively limited.

@taion
Copy link
Owner Author

taion commented Apr 12, 2016

And for what it's worth, I don't like the Express syntax for optional segments, but I feel like consistency here trumps my aesthetic preferences.

@taion
Copy link
Owner Author

taion commented Apr 12, 2016

My current thoughts for backward compatibility strategy:

  • Allow setting patternMatcher={version} on a route-by-route basis
  • Allow a top-level global static default flag for changing the pattern matcher version
  • In production mode, use the specified pattern matcher
  • In development mode, if the old pattern matcher is specified, run both pattern matchers, and warn if the results differ

@taion taion mentioned this pull request Apr 12, 2016
@taion taion closed this Apr 13, 2016
@taion taion deleted the path-to-regexp branch April 13, 2016 18:52
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 this pull request may close these issues.

1 participant