简体   繁体   English

具有多个参数的路由器不适用于 express.static

[英]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.我已经使用参数 router.get ('/add') 制作了快速路由器,并且它工作正常。 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?但是当我添加 router.get ('/edit/:id') 时,express.static 不起作用,CSS 和 JavaScript 外部不起作用,多参数有什么问题?

This my static settings这是我的静态设置

app.use(express.static(__dirname+'public')) 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. __dirname只返回你的工作目录的路径不是/目录的结束,所以你必须使用/喜欢你的静态文件目录之前。

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

for multiple parameter with URL you have to write route according your need.对于带有 URL 的多个参数,您必须根据需要编写route

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并且您的请求 URL 应如下所示

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

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

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