Map a static page
Map one Razor component to one route with MapStatic, and learn which conventions apply to every Bevel route.
On this page
app.MapStatic<HomePage>("/");
app.MapStatic<SchedulePage>("/schedule");
Each call maps one Razor component to one route. On export, / becomes index.html and /schedule becomes schedule/index.html.
app.MapStatic<SchedulePage>("/schedule");
Write the page
Create a Razor component. Use
@injectto readISiteData, your typed data.Pages/SchedulePage.razorrazor @inject ISiteData Data <h1>Schedule</h1>Map it
Call
MapStatic<TPage>(route)inProgram.cs, afterbuilder.Build().Export
Run
dotnet run -- --bevel-build. Bevel renders every mapped page into plain files.
Routes live in one place
You declare routes only in MapStatic calls. A page that declares @page "/x" is rejected. Your data has no routes either. Bevel builds links from these mappings at runtime. See Link between pages.
Conventions apply to every Bevel route
Every MapStatic* call returns a RouteHandlerBuilder. Conventions you add apply to all endpoints the call creates: the main route, the .html or index.html alias, and the first-page route of a paged mapping. WithName names the main route only.
app.MapStatic<AdminPage>("/admin/{Id}", (ISiteData d) => d.Reports)
.RequireAuthorization("Editors");
That route stops the export, because a static file cannot check who is asking. See Authorization and exports.
Group routes under a prefix
Group prefixes are part of the route. This serves, exports and links /blog/posts/x:
app.MapGroup("/blog").MapStatic<PostPage>("/posts/{Slug}", (ISiteData d) => d.Posts);
A prefix with route parameters cannot be exported.
Status-code pages
Map a 404 page and re-execute it for unknown URLs:
app.UseStatusCodePagesWithReExecute("/404.html");
app.MapStatic<NotFoundPage>("/404.html");
The page renders and keeps the original status code.