currently egg don't support sub router, but koa-router provide prefix() feature.
app.namespace([prefix], [middlewares]).verb()app.url() will traverse all the router, return the first oneexample:
// app/router.js
module.exports = app => {
app.get('/', 'home.index');
const adminRouter = app.namespace('/admin');
// GET /admin
adminRouter.get('/', 'admin.index');
// GET /admin/user
adminRouter.get('/user', 'admin.user');
}
prefix change to routerPrefix?
or just getRouter ?
发自我的 iPhone
在 2017年5月10日,21:17,Haoliang Gao notifications@github.com 写道:
prefix change to routerPrefix?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
https://github.com/eggjs/egg-core/blob/master/lib/utils/router.js#L191 没考虑 router.url(name) 怎么还原的问题?
@fengmk2 traverse all the router, return the first one?
@popomore @fengmk2 RFC and PR is updated, check again
邀请最有经验的 @huacnlee 来看看
app.verb()。const router = app.getRouter('/sub', middleware);
router.get('/test1', 'test1');
router.get('/test2', 'test2');
// or
app.namespace('/sub', middleware, router => {
router.get('/test1', 'test1');
router.get('/test2', 'test2');
});
我考虑之后单独做个 router 插件,实现一个 rails 实用的特性。
我建议加一个 advance-router 这一类的插件来实现这个需求
作为插件在Application上扩展呢?
app.namespace()如果更新了,麻烦通知下,很期待这个小功能
https://github.com/atian25/egg-router-plus/pull/1
写了个插件,下周再完善下
@atian25 你好,我用用TS写router时,提示app.router上不存在namespace这个属性。
自己写 d.ts merge 进去。还可以 PR 给这个插件。
Most helpful comment
https://github.com/atian25/egg-router-plus/pull/1
写了个插件,下周再完善下