简体   繁体   中英

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.

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>

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.

Is there something to do that?

Turns out

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

works fine...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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