Skip to content

Dynamic routes

Fiction provides full support for dynamic routing, but works different way for other popular frameworks.

Dynamic routes can be defined with fiction.serveDynamic function the same way as any other static route.

Terminal window
fiction.serveDynamic "<route>" "<function>" "<content type>"

The syntax of dynamic routes is very simple:

/<string>/[slug]/<string1>/[slug1]/...
^^^^ ^^^
static slug

If Fiction matches at least one static part of any dynamic route, it starts capturing slugs and saving them into $NAME, while the NAME is the string inside brackets

Example:

Route:
/pages/[page]
Request path:
/pages/page1
[page] => $page => page1