unjs / rou3

🌳 Lightweight and fast rou(ter) for JavaScript
MIT License
442 stars 16 forks source link

There seems to be a problem with `findAllRoutes` boundaries #124

Closed medz closed 1 month ago

medz commented 2 months ago

Environment

Bun

Reproduction

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

const router = createRouter();

addRoute(router, "get", "/path", "Static");
addRoute(router, "get", "/path/:name", "Param");

console.log(findAllRoutes(router, "get", "/path"));

Describe the bug

Register two routes: /path and /path/:name, or add another route: /path/:bar/:qaz

Use /path to call findAllRoutes, and the result includes /path/:name and /path/:bar/:qaz routes.

Additional context

No response

Logs

[
  {
    data: "Param",
    params: {
      name: undefined,
    },
  }, {
    data: "Static",
    params: undefined,
  }
]
pi0 commented 2 months ago

Thanks for report i kinda forgot to do it for findAll too before release. We need to do similar fix of #123. (feel free to PR)