V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
flyingkid
V2EX  ›  Node.js

koa-router 的一个匹配问题

  •  
  •   flyingkid · 2017-01-20 10:38:11 +08:00 · 1906 次点击
    这是一个创建于 2646 天前的主题,其中的信息可能已经有所发展或是发生改变。
    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/ 匹配失败,跳到首页

    2 条回复    2017-01-25 22:09:13 +08:00
    Arrowing
        1
    Arrowing  
       2017-01-20 17:07:22 +08:00
    自己做个中间件吧,网上有一个做好的。
    https://www.npmjs.com/package/koa-no-trailing-slash
    magicdawn
        2
    magicdawn  
       2017-01-25 22:09:13 +08:00   ❤️ 1
    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
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2744 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 12:48 · PVG 20:48 · LAX 05:48 · JFK 08:48
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.