Routes map Express-style URL Patterns to Templates. A few features of URL patterns:
The path has the ability to define parameters which populate {{req.params}}
in the rendered Template. For example, a Route which uses the URL pattern, /entries/:slug
, would pass a slug
value to its Template:
{{#entries limit="1" slug=req.params.slug}}
<h1>{{title}}</h1>
{{/entries}}
/:foo?
Optional/:foo*
Zero or more/:foo+
One or more/:foo(\\d+)
Regex support (Backslashes need to be escaped)
You can try testing Routes and parameters with the Express Route Tester.
The order of your Routes matter. Every time a user hits a page on your site, the URI (eg. /news/2014/) will attempt to match against each of your Routes, from the top of the list to the bottom.
Once a hit is made, Buckets will attempt to render its Template. If there is an error—or if the Template calls the {{next}}
tag—the current Route gets put aside and we keep going down the list.
This makes it easy to provide complex URL schemes by creating multiple Routes like "/news/:year" and "/news/:slug", and use two separate Templates for them, depending on if a match is made.