简体   繁体   English

如何设置参数有多个斜杠的快速路由?

[英]How do I set up an express route where parameters have multiple slashes?

I'm trying to set up an endpoint like below:我正在尝试设置如下端点:

http://localhost:5000/guardian/lifeandstyle/2020/apr/26/bring-your-skin-to-life-with-a-hint-of-bronzer

I currently set up my endpoint like this:我目前这样设置我的端点:

router.get('/guardian/:articleId', (req, res) => {

const id = req.params.articleId;
console.log(id);

axios.get('https://content.guardianapis.com/'+ id +'?api-key=' + guardianapi + '&show-blocks=all')
    .then(function (response) {
        res.send(response.data);
    });
});

But I'm getting a 404 error once I enter the endpoint in my browser但是,一旦我在浏览器中输入端点,就会收到 404 错误

See the guide which has an example:请参阅有示例的指南

 app.get('/users/:userId/books/:bookId', function (req, res) { res.send(req.params) })

You just put multiple / in the route and multiple names starting with a : .您只需在路线中放置多个/并以:开头的多个名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM