radix3 icon indicating copy to clipboard operation
radix3 copied to clipboard

add params property like RadixRouter.lookup to RouteMatcher.matchAll

Open demosofa opened this issue 2 years ago • 2 comments

Describe the feature

I think this is more consistent with RadixRouter.lookup as I myself was hoping for a params property. The use-case comes from the implemetation of URL's wildcard pattern where there can be multiple urls have different path parameters.

Additional information

  • [ ] Would you be willing to help implement this feature?

demosofa avatar Jul 12 '23 07:07 demosofa

Hi. Can you please elaborate more about expected new feature how API looks like?

pi0 avatar Jul 12 '23 15:07 pi0

@pi0 Hello.

If there are two routing rules:

  • /hello/:name
  • /hello/:mine

The result matcher.matchAll('/hello/world') should return (assuming no other payload) is:

[
  { params: { name: 'world' } },
  { params: { mine: 'world' } }
]

But the current version of matchAll does not carry the params field. Therefore, for matched dynamic routes, I cannot know what the dynamic parameters are.

My current requirement is to match multiple dynamic routes and have them handled by multiple handlers at the same time. I would really appreciate it if this issue could be resolved.

Hanxven avatar Aug 17 '23 12:08 Hanxven

From rou3 0.4x (#118) it is possible:

import { createRouter, addRoute, findRoute } from "rou3";

const router = createRouter();
addRoute(router, "", "/hello/:name", {});
addRoute(router, "", "/hello/:min", {});

/**
[
  { data: {}, params: [Object: null prototype] { name: 'world' } },
  { data: {}, params: [Object: null prototype] { min: 'world' } }
]
 */
console.log(findRoute(router, "GET", "/hello/world"));

pi0 avatar Jul 09 '24 19:07 pi0