Router.use() doesn't take in composed Router middleware as expected
See original GitHub issueIt’s just a quick mirror of https://github.com/ZijianHe/koa-router/issues/454, which is unresolved but closed.
node.js version: 10.16.0
npm/yarn and version: yarn 1.17.3
@koa/router
version: 8.0.6
koa
version: 2.11.0
koa-compose
version: 4.1.0
Code sample:
const app = new Koa();
const router1 = new Router();
const router2 = new Router();
router2.get('/', ctx => {
ctx.body = 'not work';
});
router1.use('/', compose([router2.routes(), router2.allowedMethods()]));
app.use(router1.routes()).use(router1.allowedMethods());
Expected Behavior:
Visit '/'
, get 'not work'
Actual Behavior:
Visit '/'
, get 'Not Found'
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:6 (3 by maintainers)
Top Results From Across the Web
router.use middleware does not get called - Stack Overflow
The middleware that doesn't get called is jwtPermission. So I have a routes folder where I have a index, and the authentication file(that...
Read more >Migrating to React Router v6: A complete guide
Migrate your React Router applications from v5 to v6 with this in-depth guide, including a review of additions and improvements from v5.
Read more >Routing - 4.x - CakePHP Cookbook
Routing ¶. class Cake\Routing\RouterBuilder¶. Routing provides you tools that map URLs to controller actions. By defining routes, you can separate how your ...
Read more >Directives • Akka HTTP - Documentation
Routes effectively are simply highly specialised functions that take a ... So, when using Akka HTTP's Routing DSL you should almost never have...
Read more >typeerror: router.use() requires a middleware function but got ...
TypeError : Router.use() requires middleware function but got a Object. And tracing the error leads me to line 32 in app.js. TraceMSG. at...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@meteorlxy
It’s not necessary use
compose
.You can see the @dominicegginton example above.
I make this way to put my
routes
together (usingcompose
):https://github.com/lagden/api-boilerplate/blob/master/server/routes/index.js
I got
@koa/router
to work withkoa-compose
like this:I’m pretty sure
middleware.router
belongs to the internal API of@koa/router
and as such may be changed without notice, but for now this appears to be working perfectly fine.