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:

 

posted @ 2019-06-12 17:53  嵌入式实操  阅读(81)  评论(0编辑  收藏  举报