[英]Express JS routing parameters
I need to use the data from quote_number parameter to create a query from this url: 我需要使用quote_number参数中的数据从此url创建查询:
http://localhost:3000/#/quote/line/?quote_number=1003 HTTP://本地主机:3000 /#/报价/线/ quote_number = 1003?
where quote_number = ${req.params.quote_number}
其中
quote_number = ${req.params.quote_number}
I'm expecting to get 1003
from this, but am getting line
as the return parameter 我期望从中得到
1003
,但是将line
作为返回参数
The URL is not correct. 网址不正确。 Because you have the # symbol, Nothing is recognized after that.
因为您有#符号,所以此后什么也不会识别。 I don't know if you're doing it because there's no additional code.
我不知道您是否正在执行此操作,因为没有其他代码。
If you try like this: 如果您这样尝试:
app.get('/quote/line/:id', (req, res) =>{
console.log(req.params);
});
URL in browser: 浏览器中的网址:
http://localhost:3000/quote/line/quote_number=1003
result: 结果:
{ quote_number: 'quote_number=1003' }
if you use query
instead of params
: 如果您使用
query
而不是params
:
app.get('/quote/line/', (req, res) =>{
console.log(req.query);
});
in browser: 在浏览器中:
http://localhost:3000/quote/line/?quote_number=1003
result: 结果:
{ quote_number: '1003' }
and now, you can get the value by 现在,您可以通过
req.query.quote_number
References: 参考文献:
req.query and req.param in ExpressJS ExpressJS中的req.query和req.param
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.