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']
    }
  }
}
πŸ“–

Community Resources

GitHub
Visit Enhance on GitHub.
Discord
Join our Discord server to chat about development and get help from the community.
Mastodon
Follow Enhance in the Fediverse. We're huge fans of the IndieWeb!