trie-router
trie-router copied to clipboard
Params support in `use`
I am not sure if that is already supported and I just don't see it. I want to "dynamically" mount a koa app with routes to a variable route like this:
const appRouter = () => {
return new Router()
.use(ctx => {
// has ctx.params.app
// has ctx.params.id if its specified in the route,
})
.get("/:id", ctx => {
// has ctx.params.app
// has ctx.params.id,
})
.middleware()
app.use(mount("/:app", appRouter()))
Which should enable routes like:
/myapp/1
/myapp/2
Even better if I could design the approuter to be totally unaware of the /:app
part of the route and only would have to deal with its own routes. Then I would like to move the processing of potential id
params to a middleware that is called before the approuter and sets some infos in the ctx
before passing control to the approuter.