Koa.js URL Building - Koa.js

How to use dynamic routes in koa.js?

Use of dynamic routes facilitates to pass parameters and process. The routes discussed in the previous chapter are fixed or static routes. Different types of routes are provided to use dynamic routes. An illustration of dynamic route is:

url building

One of the much more complex illustrations is:

url building

All the parameters passed in url can be accessed by using this.params

Note: The above mentioned illustrations are of different paths and do not overlap.

What is koa.js pattern matched routes?

Regex facilitates in restricting the URL parameter matching. For instance, if the id is desired to be 5 digits long number, the route definition is:

The requests bearing 5 digit long id are only matched. A response message Not Found appears if none of the routes match the request. The routes are validated/matched by using more complex regexes.

For instance, defining the route as above requesting with a valid URL:

correct

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Koa.js Topics