learning express step(八)

To skip the rest of the middleware functions from a router middleware stack, call next('route') to pass control to the next route.

const express = require('express');
const app = express();

app.get('/user/:id', function (req, res, next) {
        if (req.params.id === '0') next('route')
        else next()
    }, function (req, res, next) {
        res.send('regular');
    }
);

app.get('/user/:id', function (req, res, next) {
    res.send('special');
});

app.listen(3000);

web result:

原文地址:https://www.cnblogs.com/lianghong881018/p/11011221.html