-
-
Notifications
You must be signed in to change notification settings - Fork 159
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
Added support for regular expressions in paths #450
Conversation
Run & review this pull request in StackBlitz Codeflow. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## v3 #450 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 1 1
Lines 1 1
=========================================
Hits 1 1 ☔ View full report in Codecov by Sentry. |
I changed it to handle the |
@JonahPlusPlus Hey, thank you! 👏 You've done an enormous work and everything seems good. I've looked briefly, so I'm going to take some time to understand better how it works. |
Okay, so I got those changes done and I added one final change: string paths also return indices for the params as well as the keys. So, matching Future work: const idPath = cachePath("/:id");
<Route path={idPath}>
...
</Route> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing job! I have no more comments 😃
This fixes #449.
By supporting regular expressions in paths, it becomes possible to lift validation out of routes and into the paths themselves.
What happens when you use a
RegExp
:The route doesn't run the parser, but just executes the regex. After executing the regex, instead of mapping the keys and values into an object, the indices of the regex result are mapped to an object and the named groups are assigned to the object as well.
For example:
Another thing to consider: should normal paths also expose params as indices? (so, should
/:id
become{ 0: "foo", id: "foo" }
, instead of just{ id: "foo" }
?)