Add `LinearRouter.matchRoute` static method for direct matching
What is the feature you are proposing?
What is the feature you are proposing?
Introduce a LinearRouter.matchRoute static method that allows developers to use the route-matching logic directly, without needing to:
- Initialize a full router instance, and
- Add routes only to then check if a path matches.
This would simply abstract the logic already implemented in the router’s existing match function, but make it accessible as a standalone utility.
Why is this needed?
The route-matching logic is useful outside the context of a full router.
Providing matchRoute as a direct method would:
- Simplify testing (check if a path would match a given route definition).
- Help with debugging (inspect how a route resolves without building a router).
But how will you put path+handler in router? For that you need an instance of router then router.add(path, handler) then you can use router.match. But for static router.match i don't know how it will work? @yusukebe
But how will you put path+handler in router? For that you need an instance of router then router.add(path, handler) then you can use router.match. But for static router.match i don't know how it will work? @yusukebe
Router.match isn't static, check the implementation here: https://github.com/honojs/hono/pull/4410. Instead of using the whole router class to check if route path matches the actual request pathname, just use a functions. Nothing changes.