You just need to invoke the corresponding route handler function.
Option 1: route multiple paths to the same handler function
function getDogs(req, res, next) {
//...
}}
app.get('/dogs', getDogs);
app.get('/canines', getDogs);
Option 2: Invoke a separate handler function manually/conditionally
app.get('/canines', function (req, res, next) {
if (something) {
//process one way
} else {
//do a manual "forward"
getDogs(req, res, next);
}
});
Option 3: call next('route')
If you carefully order your router patterns, you can call next('route')
, which may achieve what you want. It basically says to express 'keep moving on down the router pattern list', instead of a call to next()
, which says to express 'move down the middleware list (past the router)`.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…