gpt4 book ai didi

node.js - Express中定义路由时添加route关键字的区别

转载 作者:太空宇宙 更新时间:2023-11-03 21:54:53 26 4
gpt4 key购买 nike

有什么区别

router.route('/create')
.post(验证(hotelValidation.createHotel),函数(req,res){

简单


router.post('/create', validate(hotelValidation.createHotel), function (req, res) {

这些是一样的吗?这里的route关键字有什么作用?

最佳答案

Are these the same? What does the route keyword accomplish here?

在这里它什么也没做。但你可以这样做:

app.route('/some/very/long/path/that/you/dont/want/to/duplicate/risking/errors')
.get(function (req, res) {
})
.post(function (req, res) {
})
.put(function (req, res) {
});

而不是:

  router.get('/some/very/long/path/that/you/dont/want/to/duplicate/risking/errors', function (req, res) {
})
router.post('/some/very/long/path/that/you/dont/want/to/dpulicate/risking/errors', function (req, res) {
})
router.put('/some/very/long/path/that/you/dont/want/to/dulpicate/risking/errors', function (req, res) {
});

关于node.js - Express中定义路由时添加route关键字的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43589101/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com