Skip to main content

Base Path

The basePath() method allows you to create a new Hono instance with a prefixed base path:
From src/hono-base.ts:247, basePath() creates a new instance with a merged path:

Mounting Routes with route()

The route() method allows you to mount a Hono instance at a specific path:

Implementation

From src/hono-base.ts:208, route() mounts all routes from the sub-app:

Organizing by Feature

Group related routes into separate modules:

Nested Routing

You can nest routes multiple levels deep:

Accessing Base Path Information

Use the hono/route helper to access base path information:
From src/helper/route/index.ts:106, basePath() returns the base path with embedded parameters:

Using Middleware with Groups

Apply middleware to grouped routes:

Grouping with use()

The use() method can apply middleware to multiple routes:
From src/hono-base.ts:157, the use() implementation:

Versioned APIs

Organize different API versions:

Dynamic Base Paths

Use parameters in base paths for multi-tenant applications:

Mounting External Applications

For mounting non-Hono applications, use mount():
From src/hono-base.ts:328, the mount() method:

Best Practices

Group routes by business domain or feature:
Establish a clear pattern for your API structure:
Share middleware across related routes:
Each route module should handle a single resource or feature:
Route grouping helps maintain clean, modular code and makes it easier to apply middleware and organize your application.