简体   繁体   English

响应任何子文件夹获取请求的Express.js路由

[英]Express.js route that responds to any subfolder get request

I am trying to set a route in express js that would be triggered by any query that would start with that route Url. 我试图在快速js中设置一个路由,该路由将由任何以该路由Url开头的查询触发。

For instance, I want to do the following in an html file: 例如,我想在html文件中执行以下操作:

<a href="/article/article1">Article 1</a>
<a href="/article/article2">Article 2</a>

and handle the 2 Url by a single route: 并通过一条路线处理2个网址:

app.get('/article/*',function(req,res) {
   // do something with req.path
}

I know static does that so there should be a way. 我知道静态就是这样,所以应该有办法。 I want to do this without using query parameters, because urls without query parameters feel more static, and I want to give the users this impression that the page will always work. 我想在不使用查询参数的情况下执行此操作,因为没有查询参数的网址感觉更加静态,我想给用户这样的印象,即网页将始终有效。

Is there something to do that? 有什么事可做吗?

Turns out 结果

app.get('/article/*',function(req,res) {
   // do something with req.path
}

works fine... 工作良好...

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

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