hono
hono copied to clipboard
Arrayed routes (multiple routes in single function)
What is the feature you are proposing?
Hi,
Hono currently supports multi methods but not multi routes.
app.on(['PUT', 'DELETE'], '/post', (c) => c.text('PUT or DELETE /post'))
I would like to see support with the following:
app.get(['/hello', '/jp/hello', '/en/hello'], (c) => c.text('Hello!'))
Would be great for localisation/i18n use, etc. Thanks!
Hi @morpig
Indeed, we would like to have that feature. However, type-solving and handling of path parameters are difficult.
So we do not plan to implement it at this time. Instead, although verbose, please use the following method, for example.
import { Hono } from 'hono'
import { createFactory } from 'hono/factory'
const app = new Hono()
const factory = createFactory()
const handler = factory.createHandlers((c) => c.text('Hi'))
app.get('/hello', ...handler)
app.get('/:lang{(en|jp)}/hello', ...handler)