Sierra guide / Routing
Pages and paths
The route table is derived from the file tree, and nothing is registered by hand. A lowercase .mesa or .md file is a page, and its path is its URL.
import { scan } from '@frontierjs/sierra/scanner'
import { mkdtempSync, mkdirSync, writeFileSync } from 'node:fs'
import { join } from 'node:path'
import { tmpdir } from 'node:os'
const root = mkdtempSync(join(tmpdir(), 'sierra-'))
mkdirSync(join(root, 'src/routes/blog'), { recursive: true })
mkdirSync(join(root, 'src/routes/(auth)'), { recursive: true })
for (const file of ['index.mesa', 'about.mesa', 'blog/[slug].mesa', '(auth)/login.mesa'])
writeFileSync(join(root, 'src/routes', file), '<h1>Hello</h1>')
const tree = await scan('src/routes', { cwd: root })
const paths = tree.children.map(node => node.path)
if (tree.path !== '/') throw new Error(`expected the index at /, got ${tree.path}`)
if (paths.join() !== '/about/,/blog/:slug/,/login/') throw new Error(`unexpected paths ${paths}`)
What else it can do
index.mesais its folder's page and adds no URL segment[leadId].mesais/leads/:leadId/and reads aspage.params.leadId[...rest].mesais a catch-all,docs/[...rest].mesais a catch-all below a folder, and a static or[param]sibling wins first(auth)/is a group folder and adds nothing to the URL.mdfiles route exactly like.mesafiles_module.mesais a layout, and a PascalCase or_-prefixed file is a component that is never routedabout.meta.jsis the companion that holdsmeta,loadandgetStaticPathsforabout.mesatrailingSlash: 'always' | 'never' | 'preserve'sets the URL form*.mount.jsroutes the files of another directory as if they sat beside it
In depth: Sierra README § Routing, § Path syntax