// 200
router.get('/a/:id', controller...) // http://domian.com/a/1
// 404
router.get('/a/b/:id', controller...) // http://domian.com/a/b/1
---
// 第二个路由错在哪里,请问怎么才能在二级目录下带参
Translation of this issue:
// 200
Router.get('/a/:id', controller...) // http://domian.com/a/1
// 404
Router.get('/a/b/:id', controller...) // http://domian.com/a/b/1
---
// Where is the second route wrong? How can I take the parameter in the secondary directory?
// 200
router.get('/a/:id/b/:id', controller...) // http://domian.com/a/1/b/1
// 404
router.get('/a/:id/b', controller...) // http://domian.com/a/1/b
---
// 所以我搞不明白,如果可以,我觉得我们还是先解决第一个问题,它影响了我的工作。
因为你前一个通配吃掉了后一个的啊,自己调整顺序
因为你前一个通配吃掉了后一个的啊,自己调整顺序
// 404
router.get('/a/b/:id', controller...) // http://domian.com/a/b/1
// 请问我要怎么调整,才能匹配到 http://domian.com/a/b/*
我们的能不能搞成 /: 就代表 *
你可以自己写正则式。
看 https://github.com/alexmingoia/koa-router 和 https://github.com/pillarjs/path-to-regexp 文档去。
你可以自己写正则式。
看 https://github.com/alexmingoia/koa-router 和 https://github.com/pillarjs/path-to-regexp 文档去。
文档里支持这种格式的,但事实是不可以的

谁说不支持啊。。。 你的问题在于你前一个路由干掉了后一个路由,自己调整 2 行代码的顺序
谁说不支持啊。。。 你的问题在于你前一个路由干掉了后一个路由,自己调整 2 行代码的顺序
代码只是演示啊,我每次都定义一个路由,没有冲突问题
router.get('/a/:id/b', controller...)
router.get('/c/d/:id', controller...)
都不可以的啊,你自己试下嘛
我找到问题了,是我自己的问题
@jasontsai1990 :没有关系,你也可以详细告知问题所在,没准还有和你相同问题的人。
@jasontsai1990 有问题可以随时问,没事的,不过有几点建议:
egg-init --type=simple 来初始化个最小可复现仓库,这个过程中你就会自己发现问题了,这是一种非常高效的问题定位方式。