【问题标题】:While Ejs file doesn't see css style?虽然 Ejs 文件没有看到 css 样式?
【发布时间】:2019-07-02 14:24:19
【问题描述】:

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

一点代码 app.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

【问题讨论】:

    标签: css express ejs


    【解决方案1】:

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

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

    【讨论】:

    • 在我的默认目录中:public/css/style.css 和views/events.ejs,以及views/singleevent.ejs
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-02
    • 1970-01-01
    • 1970-01-01
    • 2022-11-08
    • 1970-01-01
    • 2013-11-17
    • 1970-01-01
    相关资源
    最近更新 更多