leonsenft / path_to_regexp Goto Github PK
View Code? Open in Web Editor NEWPath matching utilities for routing.
Home Page: https://path-to-regexp.web.app
License: MIT License
Path matching utilities for routing.
Home Page: https://path-to-regexp.web.app
License: MIT License
@leonsenft Hi! thanks for your package. Can you publish null-safety to prerelease in pub.dev like other packages? Thanks )
Hello
I have seen the issue before #18 and read your comment about it
Now we do have a use case for it and I am working on a library that needs it :)
I am working on a routing library that would let you use it with ease and now with web support the library really needs a wildcard matching for routing
WouterRouterDelegate(
tag: "home",
child: WouterSwitch(
routes: {
"/": (context, [Map<String, dynamic>? data]) => MaterialPage(
child: HomeScreen(),
),
"/people": (context, [Map<String, dynamic>? data]) => MaterialPage(
child: PeopleScreen(),
),
},
),
);
under /people route:
WouterRouterDelegate.withParent(
parent: context.wouter,
tag: "people",
base: "/people",
child: WouterSwitch(
routes: {
r"/:id(\d+)": (context, [Map<String, dynamic>? data]) =>
MaterialPage(
child: PersonDetailsScreen(
person: people[data!["id"]]!,
),
),
"/": (context, [Map<String, dynamic>? data]) =>
const MaterialPage(
child: AllPeopleScreen(),
),
r"(.*)": (context, [Map<String, dynamic>? data]) =>
const MaterialPage(
child: Redirect(
to: "/people",
),
),
},
),
),
No i would like users to be able to redirect to other paths with ease and currently it is not possible
as you can see from the example above I would like to redirect users from anything that doesn't match "/" or "/:id(\d+)" back to "/people"
but not because i cant match a wildcard so I can't implement such a capability
I can't use prefix: true
as a user might not want it in other routes..
that just an easy example and the sky is the limit of course
I propose to add wildcard: bool
option that set to false
by default so then users can choose if to add support for wildcard matching or not
- How do you convert * to a path? In the branch linked above, I decided to treat it as an empty path, but it's not clear that would always be desired.
if you are referring to toPath
method you can throw an error or return null as its not something anyone should use... (maybe just generate a random path haha)
otherwise I dont see any other issues with that
- It doesn't introduce any new capability that I'm aware of. It's a slightly more convenient shorthand for writing the following path specification.
I just put on a good example :)
Ill be happy if you can consider the option to put it back in some form as I think it would be very beneficial for web libraries
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?
It would be great to be able to match optional query parameters as well as positional parameters, e.g.
route: /family/:fid
path: /family/f2?pid=p1
would be a match and provide two params, i.e. fid=f2
, pid=p1
it would also be great to build that into the route as a required parameter but not worry about order, e.g.
route: /family/:fid?:did(d\d+)
path: /family/f2?pid=p1&did=d3
since path includes fid
and did
, this would match and set the params to fid=f2
, pid=p1
and did=d3
Hi,
first thanks for the package it's great!
Maybe I'm doing something wrong but when I try to use an *
in a route, I expect it to match everything but nothing is matched, the *
is just escaped. Is this the expected behaviour?
I tried on your website
https://path-to-regexp.web.app/
And also trying the same on path-to-regexp in JavaScript, the *
matches anything, as expected:
http://forbeslindesay.github.io/express-route-tester/
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.