美文网首页
路由中间件koa-router的使用

路由中间件koa-router的使用

作者: HuFan_JS | 来源:发表于2020-03-26 22:03 被阅读0次

注册

npm i koa-router

实例化

const usersRouter = new Router({ prefix: '/users' })

添加路由

// 获取全部用户
usersRouter.get('/', find)
// 增
usersRouter.post('/', create)
// 删

加载路由中间件

app.use(usersRouter.routes).use(route.allowedMethods())

allowedMethods()的作用

自动设置ctx.status,以及response header中加上Allow之外(Allow:服务器支持哪些请求方法(如GET、POST等))

相关文章

  • 5.KOA 路由

    路由 一、依靠 ctx.request.url 手动处理 二、使用 koa-router 中间件 安装 路由用法 ...

  • koa2入门系列 Part 2

    路由中间件koa-router 在我们使用vue或者react的时候,页面跳转都会有对应都路由中间件如vue-ro...

  • 2.koa路由

    原生koa路由 index.js index.html koa-router中间件

  • Koa2学习系列03-路由koa-router——MVC 中重要

    路由 koa-router 上一节我们学习了中间件的基本概念,本节主要带大家学习下 koa-router 路由中间...

  • koa-router模块用法

    koa-router模块 koa必不可少的路由处理中间件,之前使用过koa-route模块,用法和koa-rout...

  • 从零开始的Koa实战(2) 路由

    路由将 URL 解析到对应的处理程序。这里我们将使用 Koa 的中间件 koa-router 来处理请求,将请求解...

  • koa 常用模块

    koa-router koa路由中间件https://github.com/alexmingoia/koa-rou...

  • 玩转Koa之koa-router原理解析

    本文将要分析的是经常用到的路由中间件 -- koa-router,详细的介绍了koa-router概述和实现,写的...

  • koa-router 新解法

    基于koa的路由中间件 api兼容 koa-router[https://www.npmjs.com/packag...

  • koa-router模块

    koa必不可少的路由处理中间件,之前使用过koa-route模块,用法和koa-router大致一样,但是没有ko...

网友评论

      本文标题:路由中间件koa-router的使用

      本文链接:https://www.haomeiwen.com/subject/ihcchhtx.html