-
Notifications
You must be signed in to change notification settings - Fork 1
Route Descriptions
Route Descriptions are a format for describing a URL or path-location on which you would like a particular bit of code to run. They are used by the Application class's route method.
The simplest of route-descriptions would be /, which would unify with either '$host/' or '$host/index.html'.
Or, for example, the index.html in the home directory: home/index.html. In other words, these types of routes
unify with urls that literally match the route.
Tannus routes allow the use of asterisk (*) wildcards for directory names, filenames, and file-extension-names. For example:
-
*- matches literally any URL -
*/- matches any URL with one directory name and either no base-name or a base-name of"index.html" -
*.[extension]- matches any URL with no directory name, which has a base-name at all, and has an extension-name of [extension]. For example, the route*.htmlwould match any top-level URL with an extension-name of.html. -
[basename].*- matches any URL with no directory name, which has an extension-name at all, and has a basename of [basename]. (e.g.index.*unifies with"index.html"or"index.md"or"index.json")
Tannus routes allow " parameters " to be requested in the route-description, which are then defined by the URL and passed to the Page. They are defined as follows:
-
:filename- matches any URL with no directory-name. Will also define the parameter"filename"and make it available to the Page. For instance, said route would match"index.html", or"fewp-dewp.css". It doesn't care what the value is at all, it's simply there to collect it. Once "matched", one could access thefilenameparameter withthis.parameters.get( "filename" ). -
:dir/index.html- matches any URL with any directory-name, and base-name of"index.html", while also defining'dir'as a page-parameter.
Page-Parameters can, however, be referenced more than once, and this is where a bit of validation can take place. Observe:
-
:name/:name- matches any URL in which the directory-name and base-name are the same.
With routes, you can even describe a URL with a plain ol' regular expression. Simply pop a regular expression, wrapped in parentheses, anywhere you'd put any other type of route-segment, and it validates the corresponding URL-segment against that regular-expression. For example:
(index|home\.html) will match either "index.html" or "home.html"