简体   繁体   中英

a router with multiple parameters not work with express.static

I have made the express router with parameters router.get ('/add') and it working fine. but when I added router.get ('/edit/:id'), express.static does not work, CSS and JavaScript external not working, what the problem with multiple parameters?

This my static settings

app.use(express.static(__dirname+'public'))

__dirname only returns path of your working directory not / end of your directory so you have to use / before your static file directory like.

app.use(express.static(__dirname + '/public'))

for multiple parameter with URL you have to write route according your need.

app.get('edit/:id/:value', (req, res) => {
    /** for get these value from request use */
    let id = req.params.id
    let value = req.params.value
})

and your request URL should look like

http://localhost:port/edit/34/988978898

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