在expressjs app.VERB调用中next()和next('route')有什么区别? [英] What is the difference between next() and next('route') in an expressjs app.VERB call?

查看:318
本文介绍了在expressjs app.VERB调用中next()和next('route')有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文档显示为:

app.VERB()方法提供Express中的路由功能, 其中VERB是HTTP动词之一,例如app.post().多种的 可以提供回调,所有回调均被平等对待,并且行为类似于 中间件,这些回调可能会调用的一个例外 next('route')绕过其余的路由回调.这 该机制可用于在路线上执行前提条件,然后通过 在没有理由继续的情况下控制后续路线 匹配的路线.

The app.VERB() methods provide the routing functionality in Express, where VERB is one of the HTTP verbs, such as app.post(). Multiple callbacks may be give, all are treated equally, and behave just like middleware, with the one exception that these callbacks may invoke next('route') to bypass the remaining route callback(s). This mechanism can be used to perform pre-conditions on a route then pass control to subsequent routes when there is no reason to proceed with the route matched.

绕过其余路由回调"是什么意思?我知道next()会将控制权传递给下一个匹配的路由.但是...什么功能将由next('route') ...控制?

What do they mean by "bypass the remaining route callbacks?"? I know that next() will pass control to the next matching route. But... what function will get control with next('route')...?

推荐答案

5分钟后回答自己的问题时,我讨厌它. next('route')是使用路由中间件时.因此,如果您有:

I hated it when I answer my own question 5 minutes later. next('route') is when using route middleware. So if you have:

app.get('/forum/:fid', middleware1, middleware2, function(){
  // ...
})

函数Middleware1()可以调用next()将控制权传递给Middleware2,或者调用next('route')将控制权全部传递给下一个匹配的路由.

the function middleware1() has a chance to call next() to pass control to middleware2, or next('route') to pass control to the next matching route altogether.

这篇关于在expressjs app.VERB调用中next()和next('route')有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆