Overview
Hono allows you to customize how your application behaves through initialization options, strict path routing, and lightweight minimal router presets. By selecting specific router presets or configuring options when creating your Hono instance, you can optimize your app for performance, bundle size, or specific path-matching rules.
Note
Hono defaults to a smart router setup combining RegExpRouter and TrieRouter for general use cases.
Configuration Options
Initialization and Settings
When initializing a standard Hono application, you can pass an options object to customize routing behavior and path resolution.
| Option Key | Type | Default | Description |
|---|---|---|---|
strict | boolean | true | Controls whether trailing slashes are treated as distinct paths. |
router | Router | undefined | A custom router instance to handle route matching. |
getPath | Function | undefined | A custom function to extract the path from incoming requests. |
Strict Path Routing
By default, strict routing is enabled (true), meaning a route defined as /hello will not match a request to /hello/. You can disable strict path routing by setting strict: false.
import { Hono } from 'hono'
// Disable strict path routing (trailing slashes are treated equivalently)
const app = new Hono({ strict: false })
app.get('/hello', (c) => c.text('Hello!'))Minimal Presets: Tiny and Quick
Preset Selection
If you want to reduce your application's bundle size or target specific router algorithms, Hono provides minimal entry points: hono/tiny and hono/quick.
Using hono/tiny
The hono/tiny preset uses PatternRouter, which is lightweight and well-suited for minimal bundle footprints.
import { Hono } from 'hono/tiny'
const app = new Hono()
app.get('/tiny', (c) => c.text('Running with PatternRouter'))
export default appUsing hono/quick
The hono/quick preset uses a SmartRouter configured with LinearRouter and TrieRouter.
import { Hono } from 'hono/quick'
const app = new Hono()
app.get('/quick', (c) => c.text('Running with Linear and Trie routers'))
export default appSupported Routers
Hono includes several internal routers that can be supplied via the router option or used within custom presets.
| Router Identifier | Description |
|---|---|
RegExpRouter | Matches routes using regular expressions. |
TrieRouter | Matches routes using a tree data structure. |
SmartRouter | Automatically selects the best underlying router based on registered routes. |
PatternRouter | Lightweight pattern-matching router used in hono/tiny. |
LinearRouter | Linear search router used alongside TrieRouter in hono/quick. |
Sources: src/hono.ts, src/preset/tiny.ts, src/preset/quick.ts, src/router/reg-exp-router/index.ts, src/router/smart-router/index.ts, src/router/trie-router/index.ts, src/router/pattern-router/index.ts, src/router/linear-router/index.ts.
Customizing with Factory
You can also pre-configure default application options using the Factory helper when generating multiple application instances.
import { Factory } from 'hono/factory'
const factory = new Factory({
defaultAppOptions: {
strict: false,
},
})
const app = factory.createApp()Tip
Use hono/tiny when building applications for edge environments where bundle size is strictly constrained.