1.

What Is Koa.js Url Building?

Answer»

We can now DEFINE routes, but those are static or fixed. To use DYNAMIC routes, we need to provide different TYPES of routes. Using dynamic routes allows US to pass parameters and process based on them. Here is an example of a dynamic route:

var koa = require('koa');
var router = require('koa-router');
var app = koa();
var _ = router();
_.GET('/:id', sendID);
function *sendID(){
this.body = 'The id you specified is ' + this.params.id;
}
app.use(_.routes());
app.listen(3000);

We can now define routes, but those are static or fixed. To use dynamic routes, we need to provide different types of routes. Using dynamic routes allows us to pass parameters and process based on them. Here is an example of a dynamic route:

var koa = require('koa');
var router = require('koa-router');
var app = koa();
var _ = router();
_.get('/:id', sendID);
function *sendID(){
this.body = 'The id you specified is ' + this.params.id;
}
app.use(_.routes());
app.listen(3000);



Discussion

No Comment Found