javascript - 当我渲染除主页之外的不同路线时,html 没有加载源,express-handlebars-Node.js
问题描述
我在我的 Node.js 项目中使用 express-handlebars。我正确设置了 express-handlebars。主页加载成功,没有错误但是当我渲染其他路由时 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)
快速车把设置
//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() });
});
谢谢您的帮助!
解决方案
您好,您能否分享您的目录,例如哪个文件夹包含哪个文件。我认为问题出在这一行。如果您的 style.css 在任何文件夹中。您应该这样提及
例如,如果我的 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" />
我希望它会工作。谢谢
推荐阅读
- python - 如何在 python turtle 中重置屏幕以便我可以为对象设置动画?
- python - 如何使用 for 循环在 tkinter 中创建菜单?
- onenote - 以编程方式将本地文件系统笔记本的副本发送到 Onedrive Onenote
- swift - 我可以在 UIButton.imageView 中放置静态图像吗?那是动画?
- javascript - 更改为 async/await 语法
- regex - Perl 或 Awk:匹配电影运行时间大于 5 小时
- c# - 使用线渲染器在 UI 图像中创建一个框不起作用
- php-curl - 使用从 cURL 返回的值作为授权标头进行后续调用
- android - Android 数据绑定到自定义视图
- c - 有没有办法从 bash 脚本中执行编译的 C 代码?