未捕获的语法错误:意外的标记<将params添加到快速路由时

Uncaught SyntaxError: Unexpected token < when adding params to express route

本文关键字:params 添加 路由 lt 语法 错误 意外      更新时间:2023-09-26

每次在路线中添加参数时都会出现此错误。它扰乱了我提供的html文件,并返回一个未找到的html文件而不是我提供的html文件中的js文件所以像这个作品

app.get('/polls',function(req,res){
res.sendFile(__dirname + "/public/poll.html")
})

但这不是

app.get('/polls/:id',function(req,res){
res.sendFile(__dirname + "/public/poll.html")
})

错误在客户端。除了在第1行调用error(poll.html中的js文件),但在控制台中显示poll.html的第1行之外,什么都没有。这里是它的github目录:https://github.com/tienanh2007/Voting-App

只需将publicPath: '/',放在webpack.config.js文件中的输出上