
我在我的Node.js项目中使用了express-handlebars。我正确地设置了express-handlebar.Main页面加载成功,但是当我渲染其他路由时,html没有加载css和js:
http://localhost:4000/user/signup (我只有普通格式)
http://localhost:4000/user/stylesheets/style.css net::ERR_ABORTED 404 (Not Found)
GET http://localhost:4000/user/images/logo.png 404 (Not Found)
GET http://localhost:4000/user/javascripts/jquery-3.3.1.min.js net::ERR_ABORTED 404 (Not Found)
GET http://localhost:4000/user/javascripts/bootstrap.bundle.min.js net::ERR_ABORTED 404 (Not Found)
GET http://localhost:4000/user/javascripts/all.js net::ERR_ABORTED 404 (Not Found)express-设置把手
//layout.hbs:
<head>
<title>{{title}}</title>
<link rel='stylesheet' href='stylesheets/style.css' type="text/css" />
</head>
<body>
{{> navbar}} //partial
{{{body}}}
<script src="javascripts/jquery-3.3.1.min.js"> </script>
<script src="javascripts/bootstrap.bundle.min.js"> </script>
<script src="javascripts/all.js"> </script>
</body>
</html>
//user.js
router.get("/user/signup", (req, res) => {
res.render("user/signup", { csrfToken: req.csrfToken() });
});感谢您的帮助!
发布于 2019-06-14 09:28:00
你好,你可以分享你的目录,比如哪个文件夹包含哪个文件。我认为问题是这个line.if,你的style.css在任何folder.You中都应该这样提到它
例如,如果我的style.css文件位于public/css/style.css中,我会这样写
<link rel='stylesheet' href='/css/style.css' type="text/css" />
不是这样的
<link rel='stylesheet' href='css/style.css' type="text/css" />
我希望它会work.Thanks
https://stackoverflow.com/questions/56572617
复制相似问题