css - 虽然 Ejs 文件没有看到 css 样式?

标签 css express ejs

我的 express 应用有问题。有一些 ejs 模板,其中正确应用了 css 样式文件。例如“localhost***/page”,但是当我转到“localhost***/page/secondpage”时,即使我应用它,我的 ejs 也看不到样式。

一些代码 应用程序.js

app.use(express.static(path.join(__dirname, 'public')));
//some code
app.use('/', require('./routes/index'));
app.use('/events', require('./routes/events'));

一些路线

const express = require('express');
const router = express.Router();

router.get('/', function (req, res, next) {
    let query = *db query*;
    res.locals.connection.query(query, function (error, results, fields) {
        if (error) throw error;
        res.render('index', { title: 'Events', data: results });
    });
});

router.get('/:id', function (req, res) {
    let query = *db query*;
    res.locals.connection.query(query, function (error, results, fields) {
        if (error) throw error;
        res.render('singleevent', { title: 'Event', data: results });
    });
});

localhost***/events 页面和下一页 localhost***/events/singleevent 的头部

<head>
  <meta charset="UTF-8">
  <title>
    <%= title %>|Minsk Events</title>
  <link rel="stylesheet" href="css/style.css">
</head>

There are my dirs

最佳答案

您要求提供与 html 文件相关的 css 文件。

所以如果 html 文件放在 events 下,那么 css 文件应该在: /事件/css/style.css 等等

关于css - 虽然 Ejs 文件没有看到 css 样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47932604/

相关文章:

html - 在网站上重新调整大小

html - 为什么 `textarea`和 `input`元素的第一个字母不是红色的?

node.js - Sails - 捕获导致服务器崩溃的全局适配器错误

android - 平板电脑/手机页面底部的空白

javascript - 图像仅在提供可选的 html 参数时不显示(否则显示)

node.js - res.send 之后运行函数

Node.js 在模块之间共享动态变量

javascript - 我如何在jquery中选择多个数组?

javascript - NodeJS 并发/异步生成 View 以提高性能

javascript - 单击按钮时如何使按钮下的特定 li 出现