我正在尝试渲染页面,但 Express 不会仅在具有单个参数的路由上加载静态文件
静态配置:
app.use(express.static(path.resolve(__dirname, "public")));
路线:
routes.get("/param/:id", (req, res) => res.render("page"));
错误:
Failed to load resource: the server responded with a status of 404 (Not Found)
Refused to execute script from 'http://localhost:port/param/1/assets/js/bundle.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
我已经尝试了一切;也许这与我的项目结构有关?
回购:项目议程
static
更改为:app.use(express.static(path.join(__dirname, '/public')));
/
开头,例如:<script src="/assets/js/bundle.js"></script>