kwhitley / itty-router

A little router.
MIT License
1.71k stars 77 forks source link

Question: Grouping - router.route(), to have certain routes in different files. #123

Closed socketopp closed 1 year ago

socketopp commented 1 year ago

Just tried out HonoJS before itty-router. HonoJS supported grouping

const book = new Hono()

book.get('/', (c) => c.text('List Books')) // GET /book
book.get('/:id', (c) => {
  // GET /book/:id
  const id = c.req.param('id')
  return c.text('Get Book: ' + id)
})
book.post('/', (c) => c.text('Create Book')) // POST /book

const app = new Hono()
app.route('/book', book)

Couldn't find it in this itty-routers documentation, is that something that is supported?

I thought it was a nice features because you can better divide your routes into different files.

Update Found the answer I was looking for! https://github.com/kwhitley/itty-router/issues/110

kwhitley commented 1 year ago

Yep! It does require that subroutes be aware of (and prefix base appropriately) the final url, but otherwise, no issues!