Multiple optional route parameters in Express?

前端 未结 3 811
借酒劲吻你
借酒劲吻你 2021-01-31 07:07

I am using Express to handle a route which is in the format of /articles/:year/:month/:day, where year, month and day are optional.

  • If none of the thr
3条回答
  •  孤街浪徒
    2021-01-31 08:13

    This type of route is not likely to work because of the underscores in the parameters passed.

    app.get('/products/:product_Id/buyers/:buyer_Id', function(req, res) {
      getArticles(req.params.product_Id, req.params.buyer_Id);
    }
    

    So i suggest you use the following route system if the route is not working. There you will be able to send multiple parameters.

    app.get('/products/:productId/buyers/:buyerId', function(req, res) {
      getArticles(req.params.productId, req.params.buyerId);
    }
    

提交回复
热议问题