Code Monkey home page Code Monkey logo

path_to_regexp's People

Contributors

leonsenft avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

path_to_regexp's Issues

Null safety

@leonsenft Hi! thanks for your package. Can you publish null-safety to prerelease in pub.dev like other packages? Thanks )

Matching wildcard

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

  1. 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

  1. 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

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?

matching query parameters

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.