The following paths should return a Hello World! body:
GET /hello
GET /foo/hello
GET /bar/hello
Actual Behavior:
Each route returns a 404, as koa is unable to match a route.
Each time the shared router is mounted (.routes() is called), the shared router is mutated, with the new mounted path being prefixed to the shared router. The resulting route for the shared router is /bar/foo/hello, which I believe is then tested three times.
Use case
While this can easily be avoided, it is an inconvenience and unpredictable behaviour.
A mutation is not predictable. My understanding is that routers should behave like self-contained packages that can be mounted dynamically in several places, providing the same route tree.
I wanted to reopen an issue that never got fixed in the old unmaintained koa-router. https://github.com/ZijianHe/koa-router/issues/244#issuecomment-184696207
Tested with
koa-router
version: 8.0.0koa
version: 2.7.0Code sample:
Expected Behavior:
The following paths should return a
Hello World!
body:Actual Behavior:
Each route returns a 404, as koa is unable to match a route.
Each time the shared router is mounted (
.routes()
is called), the shared router is mutated, with the new mounted path being prefixed to the shared router. The resulting route for the shared router is/bar/foo/hello
, which I believe is then tested three times.Use case
While this can easily be avoided, it is an inconvenience and unpredictable behaviour.
A mutation is not predictable. My understanding is that routers should behave like self-contained packages that can be mounted dynamically in several places, providing the same route tree.