Page Router
The Page Router handles page-specific code execution, and is defined in routes.ts.
Automatic Route Discovery (v2.0+)
New in v2.0: Pages are automatically discovered using the @page decorator. No manual route registration needed!
Using the @page Decorator
Simply decorate your page class with @page to auto-register it:
import { PageBase, page } from "@sygnal/sse-core";
@page('/')
export class HomePage extends PageBase {
protected onPrepare(): void {
console.log('Home page preparing...');
}
protected async onLoad(): Promise<void> {
console.log('Home page loaded');
}
}Wildcard Routes
Use * for dynamic paths like CMS collections:
Multiple Routes Per Page
Stack multiple @page decorators to handle multiple routes with one class:
Route Registration
In routes.ts, import your pages to trigger the decorators, then use getAllPages():
Manual Route Registration (Legacy)
You can still manually register routes if needed:
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