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,
HomePageandBlogPage.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.
import { RouteDispatcher } from "@sygnal/sse";
import { Site } from "./site";
import { HomePage } from "./page/home";
import { BlogPage } from "./page/blog";
export const routeDispatcher = (): RouteDispatcher => {
var routeDispatcher = new RouteDispatcher(Site);
routeDispatcher.routes = {
// Site pages
'/': HomePage,
'/blog/*': BlogPage,
};
return routeDispatcher;
}How this Works
Site code will be executed first.
A visit to the home page at
/will execute the code in ourHomePageclass.A visit to any blog page, e.g.
/blog/2024-in-reviewor/blog/ai-futures-2025will match our/blog/*route and execute the code in ourBlogPageclass.A visit to any other page, such as
/aboutwill execute nothing, because there is no route defined for it.A visit to
/blogby itself, which might be a blog directory page, will execute nothing, because it does not match any patterns.If you wanted
/blogto also execute yourBlogPagecode, 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