【文件属性】:
文件名称:path-match:请路由中间件
文件大小:72KB
文件格式:ZIP
更新时间:2021-05-17 05:19:15
JavaScript
考阿路径比赛
一个简单的围绕路由包装器。 与类似,不同之处在于它可以选择性地更好地处理方法。 所有这些路由器都在下面使用了,这也是Express所使用的。
const route = require ( 'koa-path-match' ) ( { /* options passed to path-to-regexp */ } )
app . use ( route ( '/:id(\\d+)' , ( ctx , next ) => {
const id = ctx . params . id
// do stuff
switch ( ctx . request . method ) {
}
} ) )
或者,您可以为每个方法创建中间件:
app . use ( route ( '/:id(\\d+)' )
. get ( async ctx => {
【文件预览】:
path-match-master
----.gitignore(108B)
----README.md(2KB)
----.github()
--------workflows()
----test()
--------.eslintrc(22B)
--------test.js(6KB)
----LICENSE(1KB)
----.eslintrc(41B)
----package.json(885B)
----lib()
--------index.js(2KB)
----package-lock.json(293KB)