--- title: 'Trailing slash' slug: trailing-slash description: 'Enforce a consistent trailing-slash policy across all routes with automatic redirects.' --- ## Trailing slash The `trailingSlash` option on `Mochi.serve()` enforces a consistent trailing-slash policy across every user route. The framework registers each route under both `/foo` and `/foo/`, then redirects requests to the non-canonical form. ```ts await Mochi.serve({ trailingSlash: 'always', routes, }); ``` ### Policy values | Value | Canonical form | Example redirect | | ---------- | -------------- | -------------------- | | `'never'` | No slash | `/about/` → `/about` | | `'always'` | Trailing slash | `/about` → `/about/` | Default: unset — neither form is redirected and only the form you registered is matched. ### Redirect status codes | Method | Status | | --------------------------------------- | ---------------------- | | `GET`, `HEAD` | 301 Moved Permanently | | All others (`POST`, `PUT`, `DELETE`, …) | 308 Permanent Redirect | 308 preserves the request method and body, so `