path_to_regexp
path_to_regexp copied to clipboard
Optional matching?
Curious if there is a way to define '/user/:id'
so that it will match /user
/user/
and /user/1
?
Similarly, could we define billing/:foo/:bar
so that only :foo
is required and bar is optional?
you can do it by setting prefix to true...
what we need is a 'any' match for example: /path/to.*
so everything that starts with /path/to
go there...
No, this package doesn't currently support optional parameters, although it seems like a reasonable feature.
As a workaround you could potentially just define multiple matchers per route (or multiple routes) to support this.
you can do it by setting prefix to true...
I don't think that would meet the requirements requested here. That approach means something like /user/anything
would match as well, which is probably not desired.
Right, the "aliases" approach is basically how we deal with this now, so you would need to define a path value of:
["user", "user/", "user/:id"]
This request is basically asking to not have to do that, but instead some streamlined syntax to express this.
are there any changes we will eventually get this feature?