"next('route')"不适用于".use()"; [英] "next('route')" doesn't work with ".use()"
本文介绍了"next('route')"不适用于".use()";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在这里做错什么了吗,还是表示只是不支持next('route')
和.use()
?
Am I doing something wrong here, or does express just not support next('route')
with .use()
?
var express = require('express')
var app = express()
app.use([
function (req, res, next) {
return next('route')
},
function (req, res, next) {
return res.send('sigma')
},
])
app.use(function (req, res, next) {
return res.send('alpha')
})
module.exports = app
这将提供字符串sigma
,并且应将字符串alpha
作为服务器.
This serves the string sigma
and should server the string alpha
.
更新:只是尝试了一下,但效果不佳.
Update: just tried this and it didn't work as well.
var express = require('express')
var app = express()
app.use('/', [
function (req, res, next) {
return next('route')
},
function (req, res, next) {
return res.send('sigma')
},
])
app.use('/', function (req, res, next) {
return res.send('alpha')
})
module.exports = app
更新,这也是
var express = require('express')
var app = express()
app.use(function (req, res, next) {
return next('route')
},
function (req, res, next) {
return res.send('sigma')
})
app.use(function (req, res, next) {
return res.send('alpha')
})
module.exports = app
推荐答案
根据节点问题#2591 :由于app.use()
定义了中间件,而不是路由",因此next('route')
与app.use()
一起使用时毫无意义.
According to the discussion in node issue #2591: since app.use()
defines middleware, and not a "route", next('route')
is meaningless when used with app.use()
.
这篇关于"next('route')"不适用于".use()";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文