Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 在express route api中添加命名参数_Node.js_Express - Fatal编程技术网

Node.js 在express route api中添加命名参数

Node.js 在express route api中添加命名参数,node.js,express,Node.js,Express,我有一条这样的快速路线: app.get('/api/v1/username/:option', function(req, res) { // do stuff }) 如何修改此路由,使URL显示选项(option=)的参数名?例如: http://localhost:8080/api/v1/johndoe/option=my-cool-option 这是一个URL段,不是一个参数 app.get('/api/v1/:username', function(req, res) {

我有一条这样的快速路线:

app.get('/api/v1/username/:option', function(req, res) {

  // do stuff

})
如何修改此路由,使URL显示选项(
option=
)的参数名?例如:

http://localhost:8080/api/v1/johndoe/option=my-cool-option

这是一个URL段,不是一个参数

app.get('/api/v1/:username', function(req, res) {
    //req.params.username would equal 'johndoe'
    //req.query.option would equal 'my-cool-option'
})
如果你想要它,就像你已经显示的网址,它会是

http://localhost:8080/api/v1/johndoe/?option=my-cool-option
注意问号
,这指定它是一个GET参数

app.get('/api/v1/:username', function(req, res) {
    //req.params.username would equal 'johndoe'
    //req.query.option would equal 'my-cool-option'
})