3 ms·
One powerful feature of the Express router (but missing here) is that it's just a middleware, making composition trivial, e.g.: const userRouter = router()
by olalonde 10y ago
One powerful feature of the Express router (but missing here) is that it's just a middleware, making composition trivial, e.g.:
const userRouter = router()
.get('/', showUser)
const usersRouter = router()
.get('/', listUsers)
.use('/:username', userRouter)
const mainRouter = router()
.use('/users', usersRouter)
- franciscop 10y agoAh that is really cool, recently a user requested a feature[1] that is basically this but I solved it in a different way [undocumented]: pagex.base = '/users'; pagex('/', listUsers); pagex('/:username', showUser); pagex.base = ''; I am still considering extend it in this way: pagex.namespace('/users', function(pagex){ pagex('/', listUsers); pagex('/:username', showUser); }); [1] https://github.com/franciscop/pagex/issues/1 https://github.com/franciscop/pagex/issues/1
- kevinsimper 10y agoWhy .namespace and not .use like express?
- franciscop 10y agoBecause it is completely unrelated to express, and even with express that is not really how it works so it'd only cause confusion