【发布时间】:2019-10-14 20:08:23
【问题描述】:
尝试在adonisjs 中使用可选参数进行路由时遇到问题。当我写不同的端点时,参数的结果也不同
这是我的路由器代码:
Route.post('product/:id_product?', 'ProductController.addProduct')
如果我在邮递员中向此端点发送参数
http://localhost:3333/shoping/product //the result of parameter is null
or
http://localhost:3333/shoping/product/1 //the result of parameter is 1
可以在console.log 中读取该参数,但如果我尝试运行此端点:
http://localhost:3333/shoping/product //the result of parameter is null
or
http://localhost:3333/shoping/product?id_product=1 //the result of parameter also null
console.log 的结果只是 null。那么我的路线有什么问题?
【问题讨论】:
标签: node.js parameters routes postman adonis.js