Render one page per item
Map a route with a token and an items delegate, and Bevel renders one page for each item in your data.
On this page
app.MapStatic<PostPage>("/posts/{Slug}", (ISiteData data) => data.Posts);
{Slug} is filled from each item's Slug property. Bevel renders one page per item.
// One page per item: {Slug} is filled from each session's Slug property.
app.MapStatic<SessionPage>("/sessions/{Slug}", (ISiteData data) => data.Sessions);
Add a token to the route
Put a token such as
{Slug}in the route. It must match a property on the item.Return the items
Pass a delegate that returns a collection. It can inject services and a
CancellationToken, and it can be async.Receive the item in the page
Declare a typed
[Parameter]:razor @code { [Parameter, EditorRequired] public BlogPost Post { get; set; } = default!; }
<p class="crumb"><a href="@(Links.To<SchedulePage>())">← Schedule</a></p>
<p class="when">
@Session.Start.ToString("dddd, MMMM d") ·
@Session.Start.ToString("HH:mm") – @Session.End.ToString("HH:mm") ·
@Session.Room
</p>
<h1>@Session.Title</h1>
<p class="by">
with <a href="@Links.To(Session.Speaker)">@Session.Speaker.Name</a>, @Session.Speaker.Role
</p>
<Markdown Source="@Session.RawMarkdown"/>
When a page has several parameters
If more than one parameter could take the item, mark the right one with [Model]. Mark exactly one.
Format tokens and walk properties
{Date:yyyy} formats a token. {Author.Handle} walks nested properties. In Development, Bevel logs one line per mapping at startup.
Fix routing errors
Mistakes fail at the MapStatic call, not at export. Each message says what to fix. Examples:
items delegate returns string, which is not a collection of items.the items are TagInfo, but PostPage has no [Parameter] that can receive a TagInfo.route token '{Nope}' does not match any property of BlogPost. Available properties: ...- A per-item mapping needs a token.
/postsalone fails with a message asking for/posts/{Slug}.
Link errors fail the export:
- No mapping renders the type: add a
MapStatic. - Two mappings render the type: use
Links.To<TPage>(item). No page '/posts/nope' exists: fix the value.
Slugs must be safe file names
Route segments are URL-decoded and checked. .., empty segments, separators, :, *, ? and Windows device names (con, nul, com1) are rejected. Two routes that differ only by case (/Foo and /foo) break on case-insensitive hosts. Put [Unique(IgnoreCase = true)] on slugs to catch this at build time.