响应任何子文件夹获取请求的Express.js路由 [英] Express.js route that responds to any subfolder get request
本文介绍了响应任何子文件夹获取请求的Express.js路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在快速js中设置一条路线,该路线将由任何以该路线Url开头的查询触发。
I am trying to set a route in express js that would be triggered by any query that would start with that route Url.
例如,我想做html文件中的以下内容:
For instance, I want to do the following in an html file:
<a href="/article/article1">Article 1</a>
<a href="/article/article2">Article 2</a>
并通过一条路线处理2个网址:
and handle the 2 Url by a single route:
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.
有什么可以做的吗?
推荐答案
结果
app.get('/article/*',function(req,res) {
// do something with req.path
}
工作正常......
works fine...
这篇关于响应任何子文件夹获取请求的Express.js路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文