eggjs / Egg Router Plus
Licence: mit
The missing router feature for eggjs
Stars: ✭ 117
Programming Languages
javascript
184084 projects - #8 most used programming language
Labels
Projects that are alternatives of or similar to Egg Router Plus
Egg 24time
A Twitter-like news and social server for Egg. 微信小程序社区全栈解决方案
Stars: ✭ 493 (+321.37%)
Mutual labels: egg, eggjs, egg-plugin
Egg Authz
egg-authz is an authorization middleware for Egg.js based on Casbin
Stars: ✭ 50 (-57.26%)
Mutual labels: egg, eggjs, egg-plugin
Cool Admin Api
cool-admin-api 是基于egg.js、typeorm、jwt等封装的api开发脚手架、快速开发api接口
Stars: ✭ 188 (+60.68%)
Mutual labels: egg, eggjs, egg-plugin
Egg Oauth2 Server
🌟 OAuth2 server plugin for egg.js based on node-oauth2-server
Stars: ✭ 174 (+48.72%)
Mutual labels: egg, eggjs, egg-plugin
Egg Cancan
cancancan like authorization plugin for Egg.js
Stars: ✭ 47 (-59.83%)
Mutual labels: egg, eggjs, egg-plugin
egg-rbac
Role Based Access Control for eggjs
Stars: ✭ 32 (-72.65%)
Mutual labels: egg, egg-plugin, eggjs
egg-parameters
Merge all parameters (ctx.params, ctx.request.query, ctx.request.body) into ctx.params like Rails application.
Stars: ✭ 24 (-79.49%)
Mutual labels: egg, egg-plugin, eggjs
Egg Mongo Native
MongoDB egg.js plugin using native driver.
Stars: ✭ 69 (-41.03%)
Mutual labels: eggjs, egg-plugin
Egg
🥚 Born to build better enterprise frameworks and apps with Node.js & Koa
Stars: ✭ 17,616 (+14956.41%)
Mutual labels: egg, eggjs
Nideadmin
【未完成】NideAdmin - 基于 Vue.js + Egg.js 的微信小程序后台框架
Stars: ✭ 35 (-70.09%)
Mutual labels: egg, eggjs
egg-router-plus
The missing router features for eggjs
Install
$ npm i egg-router-plus --save
Then mount plugin:
// {app_root}/config/plugin.js
exports.routerPlus = {
enable: true,
package: 'egg-router-plus',
};
Features
app/router/**/*.js
load 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
Support 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);
Note: prefix
and path
are not allow to be regex
, and prefix
can't be '/'.
// {app_root}/app/router.js
module.exports = app => {
const subRouter = app.router.namespace('/sub');
// curl localhost:7001/sub/test
subRouter.get('/test', app.controller.sub.test);
subRouter.get('sub_upload', '/upload', app.controller.sub.upload);
// const subRouter = app.router.namespace('/sub/:id');
// const subRouter = app.router.namespace('/sub', app.middleware.jsonp());
// output: /sub/upload
console.log(app.url('sub_upload'));
};
Known issues
- sub
redirect
is not support, useapp.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');
Questions & Suggestions
Please open an issue here.
License
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].