Enhance Routing
Enhance uses a filesystem-based router. When a file is added to the pages
or api
directory, itβs automatically available as a route.
Dynamic Route Segments
To match a dynamic segment, you can use the $segment
syntax. This allows you to match named parameters.
app/pages/docs/$lang.mjs β /docs/:lang β eg. (/docs/en)
app/pages/blog/$slug.mjs β /blog/:slug β eg. (/blog/hello-world)
app/api/users/$id.mjs β /users/:id β eg. (/users/axol)
Catch All Routes
To match all routes past a point in a URL, you can use the $$
syntax.
app/pages/docs/$$.mjs β /docs/:path β eg. (/docs/concepts/routing/)
app/pages/docs/$$.mjs β /docs/:path β eg. (/docs/concepts/styling/)
API Routes
Enhanceβs API routes are backend JSON routes designed for seamless client-side progressive enhancement. API routes are defined under app/api
and follow the same file-based routing conventions as app/pages
.
export async function get (req) {
return {
json: {
favorties: ['coffee crisp', 'smarties']
}
}
}