[英]Routes don't work in Express
我有兩條路線/emails
和/eamils/:id
:
var createRouter = function() {
var router = express.Router();
router.route('/emails/:id').get((req, res) => {
console.log('get=>/emails/id');
});
router.route('/emails').get((req, res) => {
console.log('get> /emails');
});
return router;
}
每當發送下一個請求時,就會調用第二個處理程序:
GET http://localhost:4000/rest-api/emails/?id=59
第一個使用id
參數的參數永遠不會起作用。 我怎樣才能解決這個問題?
正確的網址應為:
http://localhost:4000/rest-api/emails/59
並不是:
http://localhost:4000/rest-api/emails/?id=59
這里的id是查詢參數。
您需要使用:
http://localhost:4000/rest-api/emails/59
查詢參數不計算在內。
http://localhost:400/rest-api/emails/59
是正確的。 您使用的是參數而不是查詢 。
如果要使用查詢,其用法如下?
標志。
http://localhost:400/rest-api/emails?id=59
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.