Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why is koa-tree-router picking :param as a wildcard? #27

Closed
ajimae opened this issue Feb 28, 2024 · 1 comment
Closed

Why is koa-tree-router picking :param as a wildcard? #27

ajimae opened this issue Feb 28, 2024 · 1 comment

Comments

@ajimae
Copy link

ajimae commented Feb 28, 2024

I have the following routes which works just fine.

router.get('/note/:id', middlware);
router.get('/notes', middleware);
router.post('/note', middleware);
router.delete('/', middleware);

when I go another route instance and try registering another route as seen below I get an error.

route2.get('/request-id', middleware);

The error:

                    ^
error: wildcard route ':id' conflicts with existing children in path '/note/:id'
      at insertChild (/Users/username/**/lib/tree.ts:277:15)
      at addRoute (/Users/username/**/lib/tree.ts:229:9)
      at register (/Users/username/**/lib/router.ts:155:5)
      at all (/Users/username/**/lib/cols**.ts:175:9)
      at /Users/username/**/example/note-app/src/app.ts:64:1
272 |           "'"
273 |         );
274 |       }
272 |           "'"
273 |         );
274 |       }
275 | 
276 |       if (n.children.length > 0) {
277 |         throw new Error(
                    ^

Also, I notice if I change the order of this routes it throw the same error:

Changing this from

router.get('/note/:id', middlware);
router.get('/notes', middleware);
router.post('/note', middleware);
router.delete('/', middleware);

To this:

router.get('/notes', middleware);
router.get('/note/:id', middlware);
router.post('/note', middleware);
router.delete('/', middleware);

Doesn it have something to do with this issue

@steambap
Copy link
Owner

steambap commented Mar 1, 2024

There are some spelling error in your code example.... If I fix it, then there is no error after changing the router declaration order.

If you are seeing the wild card error, then it should be the same problem as the previous issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants