In this chapter, we've learned about routing. Routing is used for mapping HTTP request to controller's action method. There are several route types (Literal, Segment, Regex, Hostname, Scheme, Method etc.). Each route type uses different URL parts (and, possibly, other data from HTTP request) to compare the URL with the specified route template. We also learned how to write custom route class if the capabilities of standard route types are not sufficient.
The main task of a route class is to return a route match containing the set of parameters, by which a controller and action can be determined. An opposite task a route class allows to generate a URL by parameters. This feature is widely used in view layer of the application for generating hyperlinks.
Route types can be combined in a nested tree with the help of
or organized in a chain with
SimpleRouteStack router. These two routers allow to define
arbitrarily complex rules.
Routing configuration is stored in module's configuration file under the
Each module exposes its own routing rules, which are merged with other modules' configuration
upon application start up.