this plugin will auto load router define at app/router/**/*.js.
Notice: all sub routers will be loaded before app/router.js, please ensure all the sub router definitions are not conflict(better to use app.router.namespace to create different namespaces for each sub router file).
app.router.namespace
app.router.namespace(prefix, ...middlewares);
prefix - {String}, the prefix string of sub router
middlewares - {…Function}, optional group middlewares
sub redirect is not support, use app.router.redirect() or redirect to a named router.
const subRouter = app.router.namespace('/sub');
// will redirect `/sub/go` to `/anyway`, not `/sub/anyway`
subRouter.redirect('/go', '/anyway');
// just use router
router.redirect('/sub/go', '/sub/anyway');
// or redirect to a named router
subRouter.get('name_router', '/anyway', app.controller.sub.anyway);
// will redirect `/sub/go_name` to `/sub/anyway` which is named `name_router`
subRouter.redirect('/sub/go_name', 'name_router');
egg-router-plus
The missing router features for eggjs
Install
Then mount plugin:
Features
load
app/router/**/*.jsthis plugin will auto load router define at
app/router/**/*.js.Notice: all sub routers will be loaded before
app/router.js, please ensure all the sub router definitions are not conflict(better to useapp.router.namespaceto create different namespaces for each sub router file).app.router.namespace
prefix- {String}, the prefix string of sub routermiddlewares- {…Function}, optional group middlewaresSupport same as Router:
router.verb('path-match', app.controller.action);router.verb('path-match', middleware1, ..., middlewareN, app.controller.action);router.verb('router-name', 'path-match', app.controller.action);router.verb('router-name', 'path-match', middleware1, ..., middlewareN, app.controller.action);prefixandpathare not allow to beregex, andprefixcan’t be ‘/‘.Every different prefix will bind to different router instance, and all the namespaces will sort by trie tree to ensure best match.
Known issues
redirectis not support, useapp.router.redirect()or redirect to a named router.Questions & Suggestions
Please open an issue here.
License
MIT