【发布时间】:2021-06-17 20:12:05
【问题描述】:
我正在使用 Express.js 并设置了静态路径。
我要做什么:
- 提供 2 个
.hbs文件 --> (index.hbs&about.hbs) - 在两者中加载一个 Partial(标题)
- 应用一点 CSS 文件
发生了什么:
- CSS 已加载到
index.hbs,而部分未加载。 - 在加载部分内容时,
about.hbs上未加载 CSS。 - 在
about.hbs控制台窗口收到此错误:Refused to apply style from 'http://localhost:3000/public/css/homePageStyles.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
设置静态路径:
const staticPath = path.join(__dirname, "../public")
app.use(express.static(staticPath))
文件夹结构:
完整的源代码链接: https://github.com/jeeemmyy/7.-Partials
【问题讨论】:
标签: node.js express static handlebars.js