Slug Routes
Elegance supports dynamic path segments for pages that need to respond to variable URLs like blog posts, documentation pages, or user profiles.
Defining a Slug Route
A slug route is a directory whose name is wrapped in square brackets with a spread prefix:
/pages/[blog]/page.tsxThe page receives the matched segment as a typed parameter:
export default function page({ blog }: { blog: string }) { return <div>Reading: {blog}</div> }Static vs Dynamic
By default, slug routes are dynamic, meaning they're matched at request time against incoming URLs. If you want Elegance to pre-generate a fixed set of paths at build time instead, export isDynamic = false alongside a getEnumeratedRoutes function:
export const isDynamic = false; export async function getEnumeratedRoutes(): Promise<string[]> { return ["cake", "pie"]; } export default function page({ blog }: { blog: string }) { return <div>Reading: {blog}</div> }For /pages/[...blog]/page.tsx, this produces /blog/cake and /blog/pie as fully static pages at build time. getEnumeratedRoutes can be async, so fetching from a CMS or database is fine.
Segment Types
Elegance supports three kinds of dynamic segments, which can be freely combined in a path:
Standard `[param]`
Matches exactly one path segment.
/pages/[...user]/page.tsx > /alice, /bobCatch-all `[...param]`
Matches one or more segments, including slashes.
/pages/docs/[...filename]/page.tsx > /docs/intro, /docs/api/overviewOptional `:[param]`
Matches zero or one segment. The parameter will be undefined if the segment is absent.
/pages/:[lang]/page.tsx > /, /en, /frThese can be combined:
/pages/[...user]/:[tab]/page.tsx > /alice, /alice/posts, /bob/followersEnumerated Routes and Incremental Builds
When using isDynamic = false, Elegance re-runs getEnumeratedRoutes on every incremental build. even if your page file hasn't changed. This is intentional: the set of valid paths is usually driven by external data (a database, a CMS, the filesystem), and Elegance has no way to know when that data changes.
Paths that disappear between builds have their output files cleaned up automatically.