koa-router 的一个匹配问题

2017-01-20 10:38:11 +08:00
 flyingkid
const router = new KoaRouter({
  prefix: "/articles"
})
router.get("/:id/author", articles.author)
router.get("/:id/info", articles.info)
router.get("/", articles.index)
module.exports = router

/1/author 匹配成功,返回内容正常

/1/author/ 匹配失败,跳到首页

1913 次点击
所在节点    Node.js
2 条回复
Arrowing
2017-01-20 17:07:22 +08:00
自己做个中间件吧,网上有一个做好的。
https://www.npmjs.com/package/koa-no-trailing-slash
magicdawn
2017-01-25 22:09:13 +08:00
try https://github.com/magicdawn/impress-router

options.strict 默认 false, trailing slash 可选, 写成 true, 严格匹配

see path-to-regexp 文档 https://github.com/pillarjs/path-to-regexp#usage

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/335777

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX