Appearance
Express.router
TIP
返回一个单例模式的路由的实例,之后你可以在其上施加各种HTTP动作的中间件。
使用app.route()来避免重复路由名字(例如错字错误)--说的意思应该是使用app.router()这个单例方法来避免同一个路径多个路由实例。
Express
const app = express()
app.route('/events')
.all((req, res, next) => {
// runs for all HTTP verbs first
// think of it as route specific middleware!
})
.get((req, res, next) => {
res.json({})
})
.post((req, res, next) => {
// maybe add a new event...
})