Added support for regular expressions in paths#450
Conversation
|
|
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> |
molefrog
left a comment
There was a problem hiding this comment.
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
/:idbecome{ 0: "foo", id: "foo" }, instead of just{ id: "foo" }?)