Page Router
The Page Router handles page-specific code execution, and is defined in routes.ts
.
Usage Notes
First, create your Page class and give it a unique page class name like
ContactPage
.Then reference that class in the Page Router below
In this example;
We have a home page with code, and we also have a blog page with code, so we've created two Page classes,
HomePage
andBlogPage
.Home page is, of course, at a predefined path
/
.The Blog is a CMS collection with the Blog pages under
/blog/
. To represent this, we use a*
wildcard for the matching.
How this Works
Site code will be executed first.
A visit to the home page at
/
will execute the code in ourHomePage
class.A visit to any blog page, e.g.
/blog/2024-in-review
or/blog/ai-futures-2025
will match our/blog/*
route and execute the code in ourBlogPage
class.A visit to any other page, such as
/about
will execute nothing, because there is no route defined for it.A visit to
/blog
by itself, which might be a blog directory page, will execute nothing, because it does not match any patterns.If you wanted
/blog
to also execute yourBlogPage
code, you could simply add another route for'/blog`: BlogPage
.
Each route can execute only one Page class.
Each route must be unique, but you can add as many routes as you like.
Last updated