November 2018
Beginner
132 pages
2h 57m
English
Next, we will set up our router to handle routing to different pages of our application. We will use koa-router, the popular RESTful routing middleware for Koa.
Let's create a router.js file as shown, which will contain all our route definitions in the middleware folder:
touch middleware/router.js
After creating the file, we can insert the following content into it:
// ./middleware/router.jsconst KoaRouter = require('koa-router');const router = new KoaRouter();router.get('/', ctx => (ctx.body = 'Welcome to the Koa Blog!'));module.exports = router;
In the preceding code block, we require koa-router, and then create a new instance of the middleware and register a simple route for the index route.
Next, we register our ...
Read now
Unlock full access