中间件Node Express App中的下一个路由未被触发
我正在使用中间件来调用下一个路由,但由于某种原因,它没有被调用。 这里是代码:
app.get('/foo',function(req,res,next){ console.log('first route') next('route') },function(req,res,next){ // this route is never fired console.log('second route') res.send('second route') })
第二个函数没有被调用。 有任何想法吗
在第一个中间件函数中,你用下面的参数'route'
调用。 正如文档中所述,这会导致后续的callback被绕过:
您可以提供多个callback函数,其行为与中间件类似,只不过这些callback可以调用
next('route')
来绕过剩余的路由callback。
请将您的代码更改为
app.get('/foo',function(req,res,next){ console.log('first route') return next(); },function(req,res,next){ // this route is never fired console.log('second route') res.send('second route') })
- 必须res.end()与node.js快速调用?
- 在expression式中,是否可以在没有AJAX的情况下POST一个对象数组?
- Sails JS Waterlinejoin了多个模型
- Mongoose更新文档或插入新文档如果没有findID(Express REST API)
- 在Express Node.js中禁用etag标题
- 快递中间件访问req.params
- 使用Express创build反应应用程序
- 在ExpressJS中可以禁用/删除特定路由的中间件吗?
- Socket.io聊天应用程序显示检测到EventEmitter内存泄漏。 添加了11位听众。 使用emitter.setMaxListeners()